Bug 43336: Remove support for LibrisSpellcheck

The API that this feature was based on was removed by the Swedish
National Library, so we can remove the code and sysprefs from Koha.

Before testing:
- Run this SQL in the database and verify the syspref is empty:
  SELECT value FROM systempreferences WHERE variable = 'OPACdidyoumean';
- Go to Administration > Did you mean? and verify there is a box for
  LibrisSpellcheck
- Move the boxes around and click on "Save configuration"
- Run the SQL again and verify the contents of the syspref are now
  something like this:
  [{ "name": "AuthorityFile"}, { "name": "LibrisSpellcheck"}, { "name": "ExplodedTerms"}]
- Go to Administration > System preferences and search for "libris"
- Verify the two sysprefs LibrisKey and LibrisURL show up

To test:
- Apply this patch and make sure the DB update is run. In KTD you can
  do:
  $ sudo koha-upgrade-schema kohadev
  The output from this should be like this:
	Removed system preference 'LibrisKey'
	Removed system preference 'LibrisURL'
	'LibrisSpellcheck' was removed from the OPACdidyoumean syspref
- Run koha-upgrade-schema again. The output should be:
	'LibrisKey' syspref already removed
	'LibrisURL' syspref already removed
	'OPACdidyoumean' syspref does not contain a setting for 'LibrisSpellcheck'
- Run the same SQL as before and verify that LibrisSpellcheck is now
  gone:
  [{"name":"AuthorityFile"},{"name":"ExplodedTerms"}]
- Go to Administration > Did you mean? and verify there is no box
  for LibrisSpellcheck
- Move the boxes around and click on "Save configuration"
- Run the SQL again and verify that there is still no mention of
  LibrisSpellcheck
- Go to Administration > System preferences and search for "libris"
- Verify the two sysprefs LibrisKey and LibrisURL do NOT show up
- Empty the OPACdidyoumean syspref by running this SQL:
  UPDATE systempreferences SET value = '' WHERE variable = 'OPACdidyoumean';
- Run koha-upgrade-schema again. The output should be:
	'LibrisKey' syspref already removed
	'LibrisURL' syspref already removed
	'OPACdidyoumean' is not set

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Magnus Enger 2026-09-08 14:05:52 +02:00 committed by Pedro Amorim
parent 632017e022
commit 6d160313a2
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
5 changed files with 66 additions and 118 deletions

View File

@ -1,102 +0,0 @@
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 <https://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 $base = C4::Context->preference('LibrisURL');
my $search = $query->{'search'};
my $response = LWP::UserAgent->new->get( $base . "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 NAME
my $name = $plugin->NAME;
=back
=over
=item get_suggestions(query)
Sends in the search query and gets an XML with a suggestion
my $suggestions = $plugin->get_suggestions(\%query);
=back
=cut
=head1 NOTES
=cut
=head1 AUTHOR
Eivin Giske Skaaren <eskaaren@yahoo.no>
=cut

View File

@ -0,0 +1,66 @@
use Modern::Perl;
use Koha::Installer::Output qw(say_warning say_success say_info);
use JSON qw( to_json from_json );
return {
bug_number => "43336",
description => "Clean up sysprefs related to Libris spellcheck",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
# LibrisKey
my $deleted_key = $dbh->do(q{DELETE FROM systempreferences WHERE variable='LibrisKey'});
if ( $deleted_key && $deleted_key > 0 ) {
say_success( $out, "Removed system preference 'LibrisKey'" );
} else {
say_warning( $out, "'LibrisKey' syspref already removed" );
}
# LibrisURL
my $deleted_url = $dbh->do(q{DELETE FROM systempreferences WHERE variable='LibrisURL'});
if ( $deleted_url && $deleted_url > 0 ) {
say_success( $out, "Removed system preference 'LibrisURL'" );
} else {
say_warning( $out, "'LibrisURL' syspref already removed" );
}
# OPACdidyoumean
use Data::Dumper;
my $clean_data;
my $found_unwanted_setting = 0;
# Get the current value of OPACdidyoumean
my ($result) = $dbh->selectrow_array("SELECT value FROM systempreferences WHERE variable = 'OPACdidyoumean'");
if ($result) {
my $json_data = from_json($result);
# Loop over all the elements in the syspref
foreach my $element ( @{$json_data} ) {
if ( $element->{'name'} && $element->{'name'} ne 'LibrisSpellcheck' ) {
# Save the elements we are not interested in so we can save it back to the DB
push @{$clean_data}, $element;
} else {
# Do not save the setting for LibrisSpellcheck
$found_unwanted_setting = 1;
}
}
if ( $found_unwanted_setting == 0 ) {
# We did not find a setting for LibrisSpellcheck, so we can leave the OPACdidyoumean as it was
say_warning( $out, "'OPACdidyoumean' syspref does not contain a setting for 'LibrisSpellcheck'" );
} else {
# Update OPACdidyoumean, but without the setting for LibrisSpellcheck
my $new_json_data = to_json($clean_data);
$dbh->do("UPDATE systempreferences SET value = '$new_json_data' WHERE variable='OPACdidyoumean'");
say_success( $out, "'LibrisSpellcheck' was removed from the OPACdidyoumean syspref" );
}
} else {
say_warning( $out, "'OPACdidyoumean' is not set" );
}
},
};

View File

@ -408,8 +408,6 @@ INSERT INTO systempreferences ( `variable`, `value` ) VALUES
('LibraryThingForLibrariesEnabled','0'),
('LibraryThingForLibrariesID',''),
('LibraryThingForLibrariesTabbedView','0'),
('LibrisKey', ''),
('LibrisURL', 'http://api.libris.kb.se/bibspell/'),
('LimitReportsByLibrary','0'),
('LinkerConsiderDiacritics', '0'),
('LinkerConsiderThesaurus','0'),

View File

@ -21,8 +21,6 @@
<span>Suggest authorities which are relevant to the term the user searched for.</span>
[% CASE 'ExplodedTerms' %]
<span>Suggest that patrons expand their searches to include broader/narrower/related terms.</span>
[% CASE 'LibrisSpellcheck' %]
<span>Use the LIBRIS spellcheck API.</span>
[% END %]
</div>
</div>

View File

@ -398,15 +398,3 @@ Searching:
1: Redirect
0: "Don't redirect"
- to the result if a catalog search via the OPAC or staff interface returns only one record.
Did you mean/spell checking:
-
- "Swedish service for spellchecking.<br/>"
- LIBRIS spellchecking API key
- pref: LibrisKey
- . Can be obtained <a href="http://api.libris.kb.se/bibspell" target="_blank">from LIBRIS</a>.
-
- LIBRIS base URL
- pref: LibrisURL
class: url
- "Please only change this if you are sure it needs changing."