"Fossies" - the Fresh Open Source Software Archive 
Member "koha-19.11.15/Koha/SuggestionEngine/Plugin/ExplodedTerms.pm" (23 Feb 2021, 2548 Bytes) of package /linux/misc/koha-19.11.15.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "ExplodedTerms.pm" see the
Fossies "Dox" file reference documentation and the last
Fossies "Diffs" side-by-side code changes report:
20.05.06_vs_20.11.00.
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 Carp;
36 use C4::Templates qw(gettemplate); # This is necessary for translatability
37
38 use base qw(Koha::SuggestionEngine::Base);
39
40 =head2 NAME
41 my $name = $plugin->NAME;
42
43 =cut
44
45 sub NAME {
46 return 'ExplodedTerms';
47 }
48
49 =head2 VERSION
50 my $version = $plugin->VERSION;
51
52 =cut
53
54 sub VERSION {
55 return '1.0';
56 }
57
58 =head2 get_suggestions
59
60 my $suggestions = $plugin->get_suggestions(\%param);
61
62 Return suggestions for the specified search that add broader/narrower/related
63 terms to the search.
64
65 =cut
66
67 sub get_suggestions {
68 my $self = shift;
69 my $param = shift;
70
71 my $search = $param->{'search'};
72
73 return if ( $search =~ m/^(ccl=|cql=|pqf=)/ );
74 $search =~ s/(su|su-br|su-na|su-rl)[:=](\w*)/OP!$2/g;
75 return if ( $search =~ m/\w+[:=]\w+/ );
76
77 my @indexes = (
78 'su-na',
79 'su-br',
80 'su-rl'
81 );
82 my $cgi = new CGI;
83 my $template = C4::Templates::gettemplate('text/explodedterms.tt', 'opac', $cgi);
84 my @results;
85 foreach my $index (@indexes) {
86 my $thissearch = $search;
87 $thissearch = "$index:$thissearch"
88 unless ( $thissearch =~ s/OP!/$index:/g );
89 $template->{VARS}->{index} = $index;
90 my $label = $template->output;
91 push @results,
92 {
93 'search' => $thissearch,
94 relevance => 100,
95 # FIXME: it'd be nice to have some empirical measure of
96 # "relevance" in this case, but we don't.
97 label => $label
98 };
99 } return \@results;
100 }
101
102 1;