Skip to content
Browse files

[#12917055] Customize search relevancy ranking

Adds possibility to adjust relevancy ranking search by allowing
user to prioritize segments of the CCL query.  For example, a
user could specifya CCL snippet like:

    (rtype=a not format,regExpr-1=[a-z]) and language=eng

in the AdjustRelevancyRanking syspref.  This will generate a
search result which will prioritize book materials in English.
If blank entry is specified the syspref, Zebra will use the
regular relevancy ranking defined in Koha.
  • Loading branch information...
1 parent ce45e1f commit 5a6cd57521d1c5e5e3531d8f198719bb83b630a0 @rfy rfy committed with ctfliblime Feb 9, 2012
Showing with 22 additions and 2 deletions.
  1. +1 −0 cgi/admin/systempreferences.pl
  2. +6 −0 installer/data/syspref_defaults.json
  3. +15 −2 lib/C4/Search.pm
View
1 cgi/admin/systempreferences.pl
@@ -301,6 +301,7 @@ =head1 systempreferences.pl
$tabsysprefs{OPACAdvancedSearchTypes} = "Searching";
$tabsysprefs{maxItemsinSearchResults} = "Searching";
$tabsysprefs{OPACShowActiveBranchFirstInResults} = "Searching";
+$tabsysprefs{AdjustRelevancyRanking} = "Searching";
# EnhancedContent
$tabsysprefs{AmazonEnabled} = "EnhancedContent";
View
6 installer/data/syspref_defaults.json
@@ -2063,6 +2063,12 @@
"value" : "1",
"type" : "YesNo"
},
+ "AdjustRelevancyRanking" : {
+ "explanation" : "Specify CCL code to adjust the default relevancy ranking when performing a search in Zebra.",
+ "options" : null,
+ "value" : null,
+ "type" : "Textarea"
+ },
"PrintNoticesMaxLines" : {
"explanation" : "If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.",
"options" : null,
View
17 lib/C4/Search.pm
@@ -841,14 +841,18 @@ sub _build_weighted_query {
# FIELD WEIGHTING - This is largely experimental stuff. What I'm committing works
# pretty well but could work much better if we had a smarter query parser
my ( $operand, $stemmed_operand, $index ) = @_;
+ $index ||= 'kw';
my $stemming = C4::Context->preference("QueryStemming") || 0;
my $weight_fields = C4::Context->preference("QueryWeightFields") || 0;
my $fuzzy_enabled = C4::Context->preference("QueryFuzzy") || 0;
+ my $adj_rel_rank = C4::Context->preference("AdjustRelevancyRanking");
my $weighted_query .= "(rk=("; # Specifies that we're applying rank
# Keyword, or, no index specified
- if ( ( $index eq 'kw' ) || ( !$index ) ) {
+ if ( $index eq 'kw' ) {
+ $weighted_query .= qq/ (Title-cover,r1="$operand" and $adj_rel_rank ) or /
+ if ( $adj_rel_rank );
$weighted_query .=
"Title-cover,ext,r1=\"$operand\""; # exact title-cover
$weighted_query .= " or ti,ext,r2=\"$operand\""; # exact title
@@ -889,9 +893,18 @@ sub _build_weighted_query {
elsif ( $index =~ ',' ) {
$weighted_query .= " $index=\"$operand\"";
}
-
+ elsif ( $index eq 'ti' ){
+ $weighted_query .= qq/ (Title-cover,r1="$operand" and $adj_rel_rank ) or /
+ if ( $adj_rel_rank );
+ $weighted_query .= "(Title-cover,r2=\"$operand\")";
+ $weighted_query .= " or ti,r7=\"$operand\"";
+ $weighted_query .= " or ti,phr,r7=\"$operand\"";
+ $weighted_query .= " or ti,wrdl,r7=\"$operand\"";
+ }
#TODO: build better cases based on specific search indexes
else {
+ $weighted_query .= qq/ (Title-cover,r1="$operand" and $adj_rel_rank ) or /
+ if ( $adj_rel_rank );
$weighted_query .= " $index,ext,r1=\"$operand\""; # exact index
#$weighted_query .= " or (title-sort-az=0 or $index,startswithnt,st-word,r3=$operand #)";
$weighted_query .= " or $index,phr,r3=\"$operand\""; # phrase index

0 comments on commit 5a6cd57

Please sign in to comment.
Something went wrong with that request. Please try again.