parse AND queryies for field combinations from Koha
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 14 Dec 2016 00:11:57 +0000 (01:11 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 14 Dec 2016 00:11:57 +0000 (01:11 +0100)
CROSBI.pm

index 573c566..1c9869d 100644 (file)
--- a/CROSBI.pm
+++ b/CROSBI.pm
@@ -69,25 +69,27 @@ left outer join rad_projekt using (id)
 left outer join rad_godina using (id)
 left outer join rad_podrucje using (id)
 left outer join url using (id)
-where rad_ustanova.sifra = ?
        };
 
-       my @exec = (
-               130, # FIXME ustanova
-       );
+       my @and = ( qq{ rad_ustanova.sifra = ? } );
+       my @exec =  ( 130 ); # FIXME ustanova
 
-       if ( $query =~ s/^(fti_.+):// ) {
-               my $tsquery = join(' & ', split(/\s+/,$query) );
+       foreach my $and ( split(/ AND /, $query) ) {
 
-               my @or;
-               foreach my $f ( split(/,/,$1) ) {
-                       push @or, "$f @@ to_tsquery(?)";
-                       push @exec, $tsquery;
-               };
-               $sql .= "and ( " . join(" or ", @or) . ")";
-       } else {
-               warn "INVALID QUERY [$query]";
+               if ( $and =~ s/^(fti_.+):// ) {
+                       my $tsquery = join(' & ', split(/\s+/,$and) );
+
+                       my @or;
+                       foreach my $f ( split(/,/,$1) ) {
+                               push @or, "$f @@ to_tsquery(?)";
+                               push @exec, $tsquery;
+                       };
+                       push @and, "( " . join(" or ", @or) . ")";
+               } else {
+                       warn "INVALID QUERY [$query]";
+               }
        }
+       $sql .= "where " . join(" and ", @and);
 
 warn "XXX SQL = ",$sql, dump( @exec );