Bug 17600: Standardize our EXPORT_OK
[srvgit] / Koha / SuggestionEngine / Plugin / ExplodedTerms.pm
1 package Koha::SuggestionEngine::Plugin::ExplodedTerms;
2
3 # Copyright 2012 C & P Bibliography Services
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 =head1 NAME
21
22 Koha::SuggestionEngine::Plugin::ExplodedTerms - suggest searches for broader/narrower/related subjects
23
24 =head1 SYNOPSIS
25
26
27 =head1 DESCRIPTION
28
29 Plugin to suggest expanding the search by adding broader/narrower/related
30 subjects to subject searches.
31
32 =cut
33
34 use Modern::Perl;
35 use C4::Templates qw(gettemplate); # This is necessary for translatability
36
37 use base qw(Koha::SuggestionEngine::Base);
38
39 =head2 NAME
40     my $name = $plugin->NAME;
41
42 =cut
43
44 sub NAME {
45     return 'ExplodedTerms';
46 }
47
48 =head2 VERSION
49     my $version = $plugin->VERSION;
50
51 =cut
52
53 sub VERSION {
54     return '1.0';
55 }
56
57 =head2 get_suggestions
58
59     my $suggestions = $plugin->get_suggestions(\%param);
60
61 Return suggestions for the specified search that add broader/narrower/related
62 terms to the search.
63
64 =cut
65
66 sub get_suggestions {
67     my $self  = shift;
68     my $param = shift;
69
70     my $search = $param->{'search'};
71
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+/ );
75
76     my @indexes = (
77         'su-na',
78         'su-br',
79         'su-rl'
80     );
81     my $cgi = CGI->new;
82     my $template = C4::Templates::gettemplate('text/explodedterms.tt', 'opac', $cgi);
83     my @results;
84     foreach my $index (@indexes) {
85         my $thissearch = $search;
86         $thissearch = "$index:$thissearch"
87           unless ( $thissearch =~ s/OP!/$index:/g );
88         $template->{VARS}->{index} = $index;
89         my $label = $template->output;
90         push @results,
91         {
92             'search'  => $thissearch,
93             relevance => 100,
94                 # FIXME: it'd be nice to have some empirical measure of
95                 #        "relevance" in this case, but we don't.
96             label => $label
97         };
98     } return \@results;
99 }
100
101 1;