From 2bc1eae8188eb1d8a8ce57374514e1f20a50b6e6 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 14 Dec 2016 01:11:57 +0100 Subject: [PATCH] parse AND queryies for field combinations from Koha --- CROSBI.pm | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/CROSBI.pm b/CROSBI.pm index 573c566..1c9869d 100644 --- 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 ); -- 2.20.1