From e6b178bf8dcac2fd6e11cf19306394adc94cbc21 Mon Sep 17 00:00:00 2001 From: Lyon3 Team Date: Fri, 5 Dec 2014 15:58:49 +0100 Subject: [PATCH] Enable right truncation with search by relevance activated This makes slight modification in build_weighted_query function in order to make right truncation possible when QueryWeightFields syspref activated (even little ranked) Modify this syspref type from boolean to choice in order to add this possiblity as a third option : Search by relevance with right truncation --- C4/Search.pm | 13 ++++++++----- installer/data/mysql/sysprefs.sql | 2 +- installer/data/mysql/updatedatabase.pl | 6 ++++++ .../prog/en/modules/admin/preferences/searching.pref | 8 ++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 1326f69..d50d815 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1030,11 +1030,14 @@ sub _build_weighted_query { #$weighted_query .=" or kw,wrdl,r5=\"$operand\""; # word list any $weighted_query .= " or wrdl,fuzzy,r8=\"$operand\"" if $fuzzy_enabled; # add fuzzy, word list - $weighted_query .= " or wrdl,right-Truncation,r9=\"$stemmed_operand\"" - if ( $stemming and $stemmed_operand ) + if ( $stemming and $stemmed_operand ) { + $weighted_query .= " or wrdl,right-Truncation,r9=\"$stemmed_operand\"" ; # add stemming, right truncation - $weighted_query .= " or wrdl,r9=\"$operand\""; - + } elsif ( $weight_fields == 2 ) { + $weighted_query .= " or wrdl,right-Truncation,r9=\"$operand\""; + } else { + $weighted_query .= " or wrdl,r9=\"$operand\""; + } # embedded sorting: 0 a-z; 1 z-a # $weighted_query .= ") or (sort1,aut=1"; } @@ -1617,7 +1620,7 @@ sub buildQuery { # Apply Truncation if ( scalar(@$righttruncated) + scalar(@$lefttruncated) + - scalar(@$rightlefttruncated) > 0 ) + scalar(@$rightlefttruncated) > 0 and $weight_fields < 2 ) { # Don't field weight or add the index to the query, we do it here diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index c3e308f..6c4acbf 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -343,7 +343,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'), ('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'), ('QueryStemming','1',NULL,'If ON, enables query stemming','YesNo'), -('QueryWeightFields','1',NULL,'If ON, enables field weighting','YesNo'), +('QueryWeightFields','1','0|1|2','Enable field weighting research','Choice'), ('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'), ('RandomizeHoldsQueueWeight','0',NULL,'if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight','YesNo'), ('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index cf17e0b..4e47c3e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -9585,6 +9585,12 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.19.00.XXX"; +if ( CheckVersion($DBversion) ) { +$dbh->do("REPLACE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryWeightFields',1,'If ON, enables field weighting with or without automatic right truncation','0|1|2','Choice')"); + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) 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 c6a19bf..9f33d61 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 @@ -24,11 +24,11 @@ Searching: - to match words of the same base in a search (for example, a search for enabling would also match enable and enabled; REQUIRES ZEBRA). - - pref: QueryWeightFields - type: boolean + default: 1 choices: - yes: Enable - no: Disable - - ranking of search results by relevance (REQUIRES ZEBRA). + 0: Disable ranking of search results by relevance. + 1: Enable ranking of search results by relevance. + 2: Enable ranking of search results by relevance with right truncation. - - pref: OpacGroupResults default: 0 -- 1.7.10.4