From 5423abdd57f6b6a43e8cc65b19b5007e5848f96e Mon Sep 17 00:00:00 2001 From: David Roberts Date: Tue, 19 May 2020 20:12:57 +0000 Subject: [PATCH] Bug 25532: Add a wikipedia-style search suggestion feature to the OPAC This patch adds an auto-complete function to the OPAC search and a new system preference 'OPACSearchAutoComplete' To test: 1) Install the patch 2) Go to the OPAC and start typing a search term, e.g. Harry Potter 3) You should see a drop down will appear suggesting likely search terms which can be selected 4) Repeat the search, but mis-spell your search term, e.g. Hrry Potter. 5) You should still see the correctly spelled search term being offered for selection 6) Check that the search is unaffected, and still works correctly, both when logged in and not logged in. --- ...32-add_OPACWikipediaSearchSuggestions_syspref.sql | 7 +++++++ installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 7 +++++++ .../opac-tmpl/bootstrap/en/includes/opac-bottom.inc | 4 ++++ koha-tmpl/opac-tmpl/bootstrap/js/wikipedia-search.js | 20 ++++++++++++++++++++ 5 files changed, 39 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_25532-add_OPACWikipediaSearchSuggestions_syspref.sql create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/wikipedia-search.js diff --git a/installer/data/mysql/atomicupdate/bug_25532-add_OPACWikipediaSearchSuggestions_syspref.sql b/installer/data/mysql/atomicupdate/bug_25532-add_OPACWikipediaSearchSuggestions_syspref.sql new file mode 100644 index 00000000000..2630177398f --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_25532-add_OPACWikipediaSearchSuggestions_syspref.sql @@ -0,0 +1,7 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ( "OPACWikipediaSearchSuggestions", 0, NULL, "Enable a search suggestion to the OPAC Search box.","YesNo" ) }); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 25532 - Add a wikipedia-style search suggestion feature to the OPAC)\n"; +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 4ad73ef827e..c796bb47c64 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -433,6 +433,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OpacResetPassword','0','','Shows the ''Forgot your password?'' link in the OPAC','YesNo'), ('OPACResultsLibrary', 'homebranch', 'homebranch|holdingbranch', 'Defines whether the OPAC displays the holding or home branch in search results when using XSLT', 'Choice'), ('OPACResultsSidebar','','70|10','Define HTML to be included on the search results page, underneath the facets sidebar','Textarea'), +('OPACWikipediaSearchSuggestions','0','NULL','Enable search suggestions based on data entered into the search box','YesNo'), ('OPACSearchForTitleIn','
  • Other Libraries (WorldCat)
  • \n
  • Other Databases (Google Scholar)
  • \n
  • Online Stores (Bookfinder.com)
  • \n
  • Open Library (openlibrary.org)
  • ','70|10','Enter the HTML that will appear in the \'Search for this title in\' box on the detail page in the OPAC. Enter {TITLE}, {AUTHOR}, or {ISBN} in place of their respective variables in the URL. Leave blank to disable \'More Searches\' menu.','Textarea'), ('OpacSeparateHoldings','0',NULL,'Separate current branch holdings from other holdings (OPAC)','YesNo'), ('OpacSeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings (OPAC)','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 7169962c840..02f9b9b65b4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -563,6 +563,13 @@ OPAC: syntax: text/html class: code - + - pref: OPACWikipediaSearchSuggestions + default: 0 + choices: + yes: Enable + no: Disable + - "search suggestions based on data entered into the search box" + - - pref: OpacBrowseSearch default: 0 choices: diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index a32e7a56ee6..677d830e4f2 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -121,6 +121,10 @@ $.widget.bridge('uitooltip', $.ui.tooltip); [% Asset.js("js/amazonimages.js") | $raw %] [% END %] +[% IF Koha.Preference( 'OPACWikipediaSearchSuggestions' ) == 1 %] +[% Asset.js("js/wikipedia-search.js") | $raw %] +[% END %] +