- my $fuzzy_enabled = C4::Context->preference("QueryFuzzy") || 0;
-
- my $weighted_query .= " (rk=("; # Specifies that we're applying rank
- # keyword has different weight properties
- if ( ( $index =~ /kw/ ) || ( !$index ) ) {
- # a simple way to find out if this query uses an index
- if ( $operand =~ /(\=|\:)/ ) {
- $weighted_query .= " $operand";
- }
- else {
- $weighted_query .=" Title-cover,ext,r1=\"$operand\""; # title cover as exact
- $weighted_query .=" or ti,ext,r2=\"$operand\""; # exact title elsewhere
- $weighted_query .= " or ti,phr,r3=\"$operand\""; # index as phrase
- #$weighted_query .= " or any,ext,r4=$operand"; # index as exact
- #$weighted_query .=" or kw,wrdl,r5=\"$operand\""; # all the words in the query (wordlist)
- $weighted_query .= " or wrd,fuzzy,r8=\"$operand\"" if $fuzzy_enabled; # add fuzzy
- $weighted_query .= " or wrd,right-Truncation,r9=\"$stemmed_operand\"" if ($stemming and $stemmed_operand); # add stemming
- # embedded sorting: 0 a-z; 1 z-a
- #$weighted_query .= ") or (sort1,aut=1";
- }
-
- }
- #TODO: build better cases based on specific search indexes
- #elsif ( $index =~ /au/ ) {
- # $weighted_query .=" $index,ext,r1=$operand"; # index label as exact
- # #$weighted_query .= " or (title-sort-az=0 or $index,startswithnt,st-word,r3=$operand #)";
- # $weighted_query .=" or $index,phr,r3=$operand"; # index as phrase
- # $weighted_query .= " or $index,rt,wrd,r3=$operand";
- #}
- #elsif ( $index =~ /ti/ ) {
- # $weighted_query .=" Title-cover,ext,r1=$operand"; # index label as exact
- # $weighted_query .= " or Title-series,ext,r2=$operand";
- # #$weighted_query .= " or ti,ext,r2=$operand";
- # #$weighted_query .= " or ti,phr,r3=$operand";
- # #$weighted_query .= " or ti,wrd,r3=$operand";
- # $weighted_query .=" or (title-sort-az=0 or Title-cover,startswithnt,st-word,r3=$operand #)";
- # $weighted_query .=" or (title-sort-az=0 or Title-cover,phr,r6=$operand)";
- #$weighted_query .= " or Title-cover,wrd,r5=$operand";
- #$weighted_query .= " or ti,ext,r6=$operand";
- #$weighted_query .= " or ti,startswith,phr,r7=$operand";
- #$weighted_query .= " or ti,phr,r8=$operand";
- #$weighted_query .= " or ti,wrd,r9=$operand";
- #$weighted_query .= " or ti,ext,r2=$operand"; # index as exact
- #$weighted_query .= " or ti,phr,r3=$operand"; # index as phrase
- #$weighted_query .= " or any,ext,r4=$operand"; # index as exact
- #$weighted_query .= " or kw,wrd,r5=$operand"; # index as exact
- #}
- else {
- warn "WEIGHT GENERIC";
- $weighted_query .=" $index=$operand";
- #$weighted_query .=" $index,ext,r1=$operand"; # index label as exact
- #$weighted_query .= " or $index,ext,r2=$operand"; # index as exact
- #$weighted_query .=" or $index,phr,r3=$operand"; # index as phrase
- #$weighted_query .= " or $index,rt,wrd,r3=$operand";
- #$weighted_query .=" or $index,wrd,r5=$operand"; # index as word right-truncated
- #$weighted_query .= " or $index,wrd,fuzzy,r8=$operand" if $fuzzy_enabled;
- }
- $weighted_query .= "))"; # close rank specification
- return $weighted_query;
+ my $fuzzy_enabled = C4::Context->preference("QueryFuzzy") || 0;
+
+ my $weighted_query .= "(rk=("; # Specifies that we're applying rank
+
+ # Keyword, or, no index specified
+ if ( ( $index eq 'kw' ) || ( !$index ) ) {
+ $weighted_query .=
+ "Title-cover,ext,r1=\"$operand\""; # exact title-cover
+ $weighted_query .= " or ti,ext,r2=\"$operand\""; # exact title
+ $weighted_query .= " or ti,phr,r3=\"$operand\""; # phrase title
+ #$weighted_query .= " or any,ext,r4=$operand"; # exact any
+ #$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 )
+ ; # add stemming, right truncation
+ $weighted_query .= " or wrdl,r9=\"$operand\"";
+
+ # embedded sorting: 0 a-z; 1 z-a
+ # $weighted_query .= ") or (sort1,aut=1";
+ }
+
+ # Barcode searches should skip this process
+ elsif ( $index eq 'bc' ) {
+ $weighted_query .= "bc=\"$operand\"";
+ }
+
+ # Authority-number searches should skip this process
+ elsif ( $index eq 'an' ) {
+ $weighted_query .= "an=\"$operand\"";
+ }
+
+ # If the index already has more than one qualifier, wrap the operand
+ # in quotes and pass it back (assumption is that the user knows what they
+ # are doing and won't appreciate us mucking up their query
+ elsif ( $index =~ ',' ) {
+ $weighted_query .= " $index=\"$operand\"";
+ }
+
+ #TODO: build better cases based on specific search indexes
+ else {
+ $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
+ $weighted_query .=
+ " or $index,rt,wrdl,r3=\"$operand\""; # word list index
+ }
+
+ $weighted_query .= "))"; # close rank specification
+ return $weighted_query;