From 90289736c8164c81275a7ee7ac8cc87ebc04bfdc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 9 Aug 2013 14:42:00 +0100 Subject: [PATCH] Bug 6149 - Stopwords for Result Highlighting This patch adds a system preference to control stopwords used to prevent operators and other 'minor' words from being highlighted in search results when the OpacHighlightWords syspref is enabled --- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 9 +++++++++ .../prog/en/modules/admin/preferences/opac.pref | 5 ++++- koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 11 +++++++---- koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt | 15 +++++++++------ opac/opac-detail.pl | 1 + opac/opac-search.pl | 5 +++++ 7 files changed, 36 insertions(+), 11 deletions(-) diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 6bf7727..ed7b8bf 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -223,6 +223,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('opacheader','','70|10','Add HTML to be included as a custom header in the OPAC','Textarea'), ('OpacHiddenItems','','','This syspref allows to define custom rules for hiding specific items at opac. See docs/opac/OpacHiddenItems.txt for more informations.','Textarea'), ('OpacHighlightedWords','1','','If Set, then queried words are higlighted in OPAC','YesNo'), +('OpacHighlightStopWords','and|And|or|Or',NULL,'List of words to NOT highlight when OpacHitHighlight is enabled','free'), ('OpacHoldNotes','0','','Show hold notes on OPAC','YesNo'), ('OPACItemHolds','1','','Allow OPAC users to place hold on specific items. If OFF, users can only request next available copy.','YesNo'), ('OpacItemLocation','callnum','callnum|ccode|location','Show the shelving location of items in the opac','Choice'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 74aeb3e..fbc31ed 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7067,6 +7067,15 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.016"; +if ( CheckVersion($DBversion) ) { + $dbh->do( +"INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHighlightStopWords','and|And|or|Or',NULL,'List of words to NOT highlight when OpacHitHighlight is enabled','free')" + ); + print "Upgrade to $DBversion done (Bug 6149: Operator Highlighted in Search Results)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) 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 90295ef..cb70b2c 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 @@ -135,7 +135,10 @@ OPAC: choices: yes: Highlight no: "Don't highlight" - - words the patron searched for in their search results and detail pages. + - words the patron searched for in their search results and detail pages; To prevent certain words from ever being highlighted, enter a list of stopwords here + - pref: OpacHighlightedStopWords + class: multi + - (separate columns with |) - - pref: AuthorisedValueImages choices: diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index 6f45872..b0f4f70 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -57,11 +57,14 @@ } function highlightOn() { var x; - for (x in q_array) { + for (x in q_array) { q_array[x] = q_array[x].replace(/\w*:([\w])/, "$1"); - $(".title").highlight(q_array[x]); - $(".author").highlight(q_array[x]); - $(".results_summary").highlight(q_array[x]); + var myStopwords = "[% OpacHighlightedStopWords %]".split('|'); + if( $.inArray(q_array[x], myStopwords) == -1 ) { + $(".title").highlight(q_array[x]); + $(".author").highlight(q_array[x]); + $(".results_summary").highlight(q_array[x]); + } } $(".highlight_toggle").toggle(); } diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt index e1ef451..991bd19 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tt @@ -98,12 +98,15 @@ function highlightOff() { function highlightOn() { var x; for (x in q_array) { - q_array[x] = q_array[x].replace(/\w*:([\w])/, "$1"); - if ( q_array[x].length > 0 ) { - $(".title").highlight(q_array[x]); - $(".author").highlight(q_array[x]); - $(".results_summary").highlight(q_array[x]); - } + for (x in q_array) { + q_array[x] = q_array[x].replace(/\w*:([\w])/, "$1"); + var myStopwords = "[% OpacHighlightedStopWords %]".split('|'); + if ( (q_array[x].length > 0) && ($.inArray(q_array[x], myStopwords) == -1) ) { + $(".title").highlight(q_array[x]); + $(".author").highlight(q_array[x]); + $(".results_summary").highlight(q_array[x]); + } + } } $(".highlight_toggle").toggle(); } diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index d1f5d91..5d037c1 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -1053,6 +1053,7 @@ $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopup if (C4::Context->preference('OpacHighlightedWords')) { $template->{VARS}->{query_desc} = $query->param('query_desc'); + $template->{VARS}->{OpacHighlightedStopWords} = C4::Context->preference('OpacHighlightedStopWords'); } $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks'); diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 7d2b7a6..4275149 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -616,6 +616,11 @@ for (my $i=0;$i<@servers;$i++) { $total = $total + $results_hashref->{$server}->{"hits"}; } + # Add Stopwrods for query highlighting + if (C4::Context->preference('OpacHighlightedWords')) { + $template->{VARS}->{OpacHighlightedStopWords} = C4::Context->preference('OpacHighlightedStopWords'); + } + # Opac search history my $newsearchcookie; if (C4::Context->preference('EnableOpacSearchHistory')) { -- 1.8.1.2