1 package Koha::SuggestionEngine::Plugin::LibrisSpellcheck;
2 # Copyright (C) 2015 Eivin Giske Skaaren
4 # This file is part of Koha.
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.
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.
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>.
21 use XML::Simple qw(XMLin);
23 use base qw(Koha::SuggestionEngine::Base);
26 return 'LibrisSpellcheck';
30 my ($self, $query) = @_;
31 my $key = C4::Context->preference('LibrisKey');
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/);
40 if ($xml->{suggestion}->{term}) {
41 for (@{$xml->{suggestion}->{term}}) {
44 $label = join(' ', @terms);
46 return; # No result from LIBRIS
52 'search' => $label, #$thissearch,
54 # FIXME: it'd be nice to have some empirical measure of
55 # "relevance" in this case, but we don't.
66 Koha::SuggestionEngine::Plugin::LibrisSpellcheck
70 This module provides facilities for using the LIBRIS spell checker API
74 =item get_suggestions(query)
76 Sends in the search query and gets an XML with a suggestion
88 Eivin Giske Skaaren <eskaaren@yahoo.no>