View | Details | Raw Unified | Return to bug 14457
Collapse All | Expand All

(-)a/Koha/SuggestionEngine/Plugin/LibrisSpellcheck.pm (+90 lines)
Line 0 Link Here
1
package Koha::SuggestionEngine::Plugin::LibrisSpellcheck;
2
# Copyright (C) 2015 Eivin Giske Skaaren
3
#
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
use LWP::UserAgent;
21
use XML::Simple qw(XMLin);
22
use C4::Context;
23
use base qw(Koha::SuggestionEngine::Base);
24
25
sub NAME {
26
    return 'LibrisSpellcheck';
27
}
28
29
sub get_suggestions {
30
    my ($self, $query) = @_;
31
    my $key = C4::Context->preference('LibrisKey');    
32
33
    my $search = $query->{'search'};
34
    my $response = LWP::UserAgent->new->get("http://api.libris.kb.se/bibspell/spell?query={$search}&key=$key");
35
    my $xml = XMLin($response->content, NoAttr => 1, ForceArray => qr/term/);
36
37
    my @terms;
38
    my $label;
39
    
40
    if ($xml->{suggestion}->{term}) {
41
        for (@{$xml->{suggestion}->{term}}) {
42
            push @terms, $_;
43
        }
44
        $label = join(' ', @terms);
45
    } else {
46
        return; # No result from LIBRIS 
47
    }
48
49
    my @results;
50
    push @results,
51
    {
52
        'search'  => $label,  #$thissearch,
53
        relevance => 100,
54
            # FIXME: it'd be nice to have some empirical measure of
55
            #        "relevance" in this case, but we don't.
56
        label => $label
57
    };
58
    return \@results;
59
}
60
61
1;
62
__END__
63
64
=head1 NAME
65
66
Koha::SuggestionEngine::Plugin::LibrisSpellcheck
67
68
=head2 FUNCTIONS
69
70
This module provides facilities for using the LIBRIS spell checker API
71
72
=over
73
74
=item get_suggestions(query)
75
76
Sends in the search query and gets an XML with a suggestion
77
78
=back
79
80
=cut
81
82
=head1 NOTES
83
84
=cut
85
86
=head1 AUTHOR
87
88
Eivin Giske Skaaren <eskaaren@yahoo.no>
89
90
=cut
(-)a/installer/data/mysql/atomicupdate/bug_14557_add_libriskey_syspref.sql (+1 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('LibrisKey', '', 'This key must be obtained at http://api.libris.kb.se/. It is unique for the IP of the server.', NULL, 'Free');
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/didyoumean.tt (-1 / +3 lines)
Lines 12-18 Link Here
12
        [% CASE 'ExplodedTerms' %]
12
        [% CASE 'ExplodedTerms' %]
13
            Suggest that patrons expand their searches to include
13
            Suggest that patrons expand their searches to include
14
            broader/narrower/related terms.
14
            broader/narrower/related terms.
15
        [% END %]
15
        [% CASE 'LibrisSpellcheck' %]
16
	    Use the LIBRIS spellcheck API.
17
	[% END %]
16
        </div>
18
        </div>
17
    </div>
19
    </div>
18
[% END %]
20
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+5 lines)
Lines 221-223 Searching: Link Here
221
                  yes: "search"
221
                  yes: "search"
222
                  no: "don't search"
222
                  no: "don't search"
223
            - on all variations of the ISBN. Note that this preference has no effect if UseQueryParser is on.
223
            - on all variations of the ISBN. Note that this preference has no effect if UseQueryParser is on.
224
    API Keys:
225
        -
226
            - LIBRIS Spellcheking API key
227
            - pref: LibrisKey
228
            - "Can be obtained at http://api.libris.kb.se/bibspell."
(-)a/opac/opac-search.pl (-10 / +8 lines)
Lines 189-202 if ($cgi->param("returntosearch")) { Link Here
189
}
189
}
190
if ($cgi->cookie("search_path_code")) {
190
if ($cgi->cookie("search_path_code")) {
191
    my $pathcode = $cgi->cookie("search_path_code");
191
    my $pathcode = $cgi->cookie("search_path_code");
192
    if ($pathcode eq '"ads"') {
192
    given ($pathcode)
193
        $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?returntosearch=1');
193
    {
194
    }
194
        when ('"ads"') { $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?returntosearch=1'); }
195
    elsif ($pathcode eq '"exs"') {
195
        when ('"exs"') {
196
         $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?expanded_options=1&returntosearch=1');
196
            $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?expanded_options=1&returntosearch=1');
197
    }
197
        }
198
    else {
198
        default {warn "ReturnPath swith error";}
199
        warn "ReturnPath switch error";
200
    }
199
    }
201
}
200
}
202
201
Lines 579-585 if ($tag) { Link Here
579
# This sorts the facets into alphabetical order
578
# This sorts the facets into alphabetical order
580
if ($facets) {
579
if ($facets) {
581
    foreach my $f (@$facets) {
580
    foreach my $f (@$facets) {
582
        $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ];
581
        $f->{facets} = [ sort { uc($a->{facet_title_value}) cmp uc($b->{facet_title_value}) } @{ $f->{facets} } ];
583
    }
582
    }
584
    @$facets = sort {$a->{expand} cmp $b->{expand}} @$facets;
583
    @$facets = sort {$a->{expand} cmp $b->{expand}} @$facets;
585
}
584
}
586
- 

Return to bug 14457