Bugzilla – Attachment 40816 Details for
Bug 14457
Integrate LIBRIS spellchecking
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14457: Integrate LIBRIS spellchecking
Bug-14457-Integrate-LIBRIS-spellchecking.patch (text/plain), 7.46 KB, created by
Eivin Giske Skaaren
on 2015-07-06 22:29:52 UTC
(
hide
)
Description:
Bug 14457: Integrate LIBRIS spellchecking
Filename:
MIME Type:
Creator:
Eivin Giske Skaaren
Created:
2015-07-06 22:29:52 UTC
Size:
7.46 KB
patch
obsolete
>From 7114d3d55b47e78bbd739cf667032a2b51b1aa16 Mon Sep 17 00:00:00 2001 >From: Eivin Giske Skaaren <eskaaren@yahoo.no> >Date: Mon, 6 Jul 2015 21:46:49 +0000 >Subject: [PATCH] Bug 14457: Integrate LIBRIS spellchecking >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >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 >--- > Koha/SuggestionEngine/Plugin/LibrisSpellcheck.pm | 90 ++++++++++++++++++++ > .../bug_14557_add_libriskey_syspref.sql | 1 + > .../prog/en/modules/admin/didyoumean.tt | 4 +- > .../en/modules/admin/preferences/searching.pref | 5 ++ > opac/opac-search.pl | 17 ++-- > 5 files changed, 107 insertions(+), 10 deletions(-) > create mode 100644 Koha/SuggestionEngine/Plugin/LibrisSpellcheck.pm > create mode 100644 installer/data/mysql/atomicupdate/bug_14557_add_libriskey_syspref.sql > >diff --git a/Koha/SuggestionEngine/Plugin/LibrisSpellcheck.pm b/Koha/SuggestionEngine/Plugin/LibrisSpellcheck.pm >new file mode 100644 >index 0000000..cd66897 >--- /dev/null >+++ b/Koha/SuggestionEngine/Plugin/LibrisSpellcheck.pm >@@ -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 >diff --git a/installer/data/mysql/atomicupdate/bug_14557_add_libriskey_syspref.sql b/installer/data/mysql/atomicupdate/bug_14557_add_libriskey_syspref.sql >new file mode 100644 >index 0000000..4f36288 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_14557_add_libriskey_syspref.sql >@@ -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'); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/didyoumean.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/didyoumean.tt >index fd9dfe1..e98463b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/didyoumean.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/didyoumean.tt >@@ -12,7 +12,9 @@ > [% CASE 'ExplodedTerms' %] > Suggest that patrons expand their searches to include > broader/narrower/related terms. >- [% END %] >+ [% CASE 'LibrisSpellcheck' %] >+ Use the LIBRIS spellcheck API. >+ [% END %] > </div> > </div> > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >index 8b04d39..27fcdb6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >@@ -221,3 +221,8 @@ Searching: > yes: "search" > no: "don't search" > - 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." >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index 81f2bbb..0ff2507 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -189,14 +189,13 @@ if ($cgi->param("returntosearch")) { > } > if ($cgi->cookie("search_path_code")) { > my $pathcode = $cgi->cookie("search_path_code"); >- if ($pathcode eq '"ads"') { >- $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?returntosearch=1'); >- } >- elsif ($pathcode eq '"exs"') { >- $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?expanded_options=1&returntosearch=1'); >- } >- else { >- warn "ReturnPath switch error"; >+ given ($pathcode) >+ { >+ when ('"ads"') { $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?returntosearch=1'); } >+ when ('"exs"') { >+ $template->param('ReturnPath' => '/cgi-bin/koha/opac-search.pl?expanded_options=1&returntosearch=1'); >+ } >+ default {warn "ReturnPath swith error";} > } > } > >@@ -579,7 +578,7 @@ if ($tag) { > # This sorts the facets into alphabetical order > if ($facets) { > foreach my $f (@$facets) { >- $f->{facets} = [ sort { uc($a->{facet_label_value}) cmp uc($b->{facet_label_value}) } @{ $f->{facets} } ]; >+ $f->{facets} = [ sort { uc($a->{facet_title_value}) cmp uc($b->{facet_title_value}) } @{ $f->{facets} } ]; > } > @$facets = sort {$a->{expand} cmp $b->{expand}} @$facets; > } >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14457
:
40816
|
40827
|
45967
|
55948
|
56609
|
86569
|
87374
|
87375
|
87376
|
87377