1 package Koha::SuggestionEngine::Plugin::ExplodedTerms;
3 # Copyright 2012 C & P Bibliography Services
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 Koha::SuggestionEngine::Plugin::ExplodedTerms - suggest searches for broader/narrower/related subjects
29 Plugin to suggest expanding the search by adding broader/narrower/related
30 subjects to subject searches.
36 use base qw(Koha::SuggestionEngine::Base);
38 use Koha::I18N qw(__);
41 my $name = $plugin->NAME;
46 return 'ExplodedTerms';
50 my $version = $plugin->VERSION;
58 =head2 get_suggestions
60 my $suggestions = $plugin->get_suggestions(\%param);
62 Return suggestions for the specified search that add broader/narrower/related
68 my ( $self, $param ) = @_;
70 my $search = $param->{'search'};
72 return if ( $search =~ m/^(ccl=|cql=|pqf=)/ );
73 $search =~ s/(su|su-br|su-na|su-rl)[:=](\w*)/OP!$2/g;
74 return if ( $search =~ m/\w+[:=]\w+/ );
76 my $indexes_to_label = {
77 'su-na' => __('Search also for narrower subjects'),
78 'su-br' => __('Search also for broader subjects'),
79 'su-rl' => __('Search also for related subjects'),
83 foreach my $index ( keys %{$indexes_to_label} ) {
84 my $thissearch = $search;
85 $thissearch = "$index:$thissearch"
86 unless ( $thissearch =~ s/OP!/$index:/g );
88 'search' => $thissearch,
91 # FIXME: it'd be nice to have some empirical measure of
92 # "relevance" in this case, but we don't.
93 label => $indexes_to_label->{$index}