dealing with >=, <= and date stuff in NoZebra
authorPaul POULAIN <paul@koha-fr.org>
Thu, 8 Nov 2007 19:00:25 +0000 (13:00 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Fri, 9 Nov 2007 00:01:52 +0000 (18:01 -0600)
- if the user search on >= or <=, fix a bug removing the < and >
- if the user search on a numeric value (mainly for dates search), retrieve only numeric results

Example : previously Date >=2005 returned "printed in 1976", as "printed" was > than 2005
now it don't.
note that Date >=1900 returns "printed in 1976" as NZ search is a always wrdl search (and, as you know 1976 > 1900 ;-) )

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Search.pm

index 8de44b9..907e410 100644 (file)
@@ -1237,10 +1237,16 @@ sub NZanalyse {
         $string =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|&|\+|\*|\// /g;
 #         warn "leaf : $string\n";
         # parse the string in in operator/operand/value again
-        $string =~ /(.*)(=|>|>=|<|<=)(.*)/;
+        $string =~ /(.*)(>=|<=)(.*)/;
         my $left = $1;
         my $operator = $2;
         my $right = $3;
+        unless ($operator) {
+            $string =~ /(.*)(>|<|=)(.*)/;
+            $left = $1;
+            $operator = $2;
+            $right = $3;
+        }
         my $results;
         # automatic replace for short operators
         $left='title' if $left =~ '^ti';
@@ -1253,17 +1259,19 @@ sub NZanalyse {
             #do a specific search
             my $dbh = C4::Context->dbh;
             $operator='LIKE' if $operator eq '=' and $right=~ /%/;
-            my $sth = $dbh->prepare("SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value $operator ?");
-            warn "$left / $operator / $right\n";
+            my $sth = $dbh->prepare("SELECT biblionumbers,value FROM nozebra WHERE server=? AND indexname=? AND value $operator ?");
+            warn "$left / $operator / $right\n";
             # split each word, query the DB and build the biblionumbers result
             foreach (split / /,$right) {
-                my $biblionumbers;
+                my ($biblionumbers,$value);
                 next unless $_;
-                warn "EXECUTE : $server, $left, $_";
+                warn "EXECUTE : $server, $left, $_";
                 $sth->execute($server, $left, $_);
-                while (my $line = $sth->fetchrow) {
-                    $biblionumbers .= $line;
-#                     warn "result : $line";
+                while (my ($line,$value) = $sth->fetchrow) {
+                    # if we are dealing with a numeric value, use only numeric results (in case of >=, <=, > or <)
+                    # otherwise, fill the result
+                    $biblionumbers .= $line unless ($right =~ /\d/ && $value =~ /\D/);
+                    warn "result : $value ". ($right =~ /\d/) . "==".(!$value =~ /\d/) ;#= $line";
                 }
                 # do a AND with existing list if there is one, otherwise, use the biblionumbers list as 1st result list
                 if ($results) {