Bug 14457: Integrate LIBRIS spellchecking

This patch makes it possible to configure LIBRIS spellchecker as a
"did you mean" feature. When searching for a word or phrase and misspelling
the query will be sent to LIBRIS and if they have a suggestion it will
be shown in the yellow did you mean box in the results page.

The API is not very quick so this type of implementation was chosen to not
disrupt the real-time feeling of the search.

To test:

1. Apply the patch.
2. Go to http://api.libris.kb.se/bibspell/, enter the koha servers IP and click
on the "Generera nyckel" button.
3. Under "Nyckel" you can copy the value that looks like this: E47B44829E265607274B677BC17B8D78,
and enter it into the LibrisKey syspref (cgi-bin/koha/admin/preferences.pl?tab=searching).
4. In cgi-bin/koha/admin/didyoumean.pl check the box for using the LIBRIS API. It is only implemented for OPAC.
5. Perform some searches:
tset - Did you mean should suggest: test
jeg är på smester - suggestion: jag är på semester
dantes inferna - suggestion: dantes inferno

Restored opac-search.pl

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Seems to work, of course I can't tell if it is giving me accurate
suggestions :)

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Eivin Giske Skaaren 2015-07-06 21:46:49 +00:00 committed by Nick Clemens
parent b74be6724b
commit 37970eead1
4 changed files with 99 additions and 1 deletions

View file

@ -0,0 +1,90 @@
package Koha::SuggestionEngine::Plugin::LibrisSpellcheck;
# Copyright (C) 2015 Eivin Giske Skaaren
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use LWP::UserAgent;
use XML::Simple qw(XMLin);
use C4::Context;
use base qw(Koha::SuggestionEngine::Base);
sub NAME {
return 'LibrisSpellcheck';
}
sub get_suggestions {
my ($self, $query) = @_;
my $key = C4::Context->preference('LibrisKey');
my $search = $query->{'search'};
my $response = LWP::UserAgent->new->get("http://api.libris.kb.se/bibspell/spell?query={$search}&key=$key");
my $xml = XMLin($response->content, NoAttr => 1, ForceArray => qr/term/);
my @terms;
my $label;
if ($xml->{suggestion}->{term}) {
for (@{$xml->{suggestion}->{term}}) {
push @terms, $_;
}
$label = join(' ', @terms);
} else {
return; # No result from LIBRIS
}
my @results;
push @results,
{
'search' => $label, #$thissearch,
relevance => 100,
# FIXME: it'd be nice to have some empirical measure of
# "relevance" in this case, but we don't.
label => $label
};
return \@results;
}
1;
__END__
=head1 NAME
Koha::SuggestionEngine::Plugin::LibrisSpellcheck
=head2 FUNCTIONS
This module provides facilities for using the LIBRIS spell checker API
=over
=item get_suggestions(query)
Sends in the search query and gets an XML with a suggestion
=back
=cut
=head1 NOTES
=cut
=head1 AUTHOR
Eivin Giske Skaaren <eskaaren@yahoo.no>
=cut

View file

@ -0,0 +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');

View file

@ -15,7 +15,9 @@
[% CASE 'ExplodedTerms' %] [% CASE 'ExplodedTerms' %]
Suggest that patrons expand their searches to include Suggest that patrons expand their searches to include
broader/narrower/related terms. broader/narrower/related terms.
[% END %] [% CASE 'LibrisSpellcheck' %]
Use the LIBRIS spellcheck API.
[% END %]
</div> </div>
</div> </div>
[% END %] [% END %]

View file

@ -243,3 +243,8 @@ Searching:
yes: "search" yes: "search"
no: "don't search" no: "don't search"
- on all variations of the ISBN. Note that this preference has no effect if UseQueryParser is on. - on all variations of the ISBN. Note that this preference has no effect if UseQueryParser is on.
API Keys:
-
- LIBRIS Spellcheking API key
- pref: LibrisKey
- "Can be obtained at http://api.libris.kb.se/bibspell."