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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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.
37 use C4::Templates qw(gettemplate); # This is necessary for translatability
39 use base qw(Koha::SuggestionEngine::Base);
40 our $NAME = 'ExplodedTerms';
43 =head2 get_suggestions
45 my $suggestions = $plugin->get_suggestions(\%param);
47 Return suggestions for the specified search that add broader/narrower/related
56 my $search = $param->{'search'};
58 return if ( $search =~ m/^(ccl=|cql=|pqf=)/ );
59 $search =~ s/(su|su-br|su-na|su-rl)[:=](\w*)/OP!$2/g;
60 return if ( $search =~ m/\w+[:=]\w+/ );
68 my $template = C4::Templates::gettemplate('text/explodedterms.tt', 'opac', $cgi);
70 foreach my $index (@indexes) {
71 my $thissearch = $search;
72 $thissearch = "$index=$thissearch"
73 unless ( $thissearch =~ s/OP!/$index=/g );
74 $template->{VARS}->{index} = $index;
75 my $label = pack("U0a*", $template->output); #FIXME: C4::Templates is
76 # returning incorrectly-marked UTF-8. This fixes the problem, but is
77 # an annoying workaround.
80 'search' => $thissearch,
82 # FIXME: it'd be nice to have some empirical measure of
83 # "relevance" in this case, but we don't.