Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
sub buildQuery {
my ( $operators, $operands, $indexes, $limits, $sort_by, $scan) = @_;
sub buildQuery {
my ( $operators, $operands, $indexes, $limits, $sort_by, $scan) = @_;
+ warn "---------" if $DEBUG;
+ warn "Enter buildQuery" if $DEBUG;
+ warn "---------" if $DEBUG;
+
my @operators = @$operators if $operators;
my @indexes = @$indexes if $indexes;
my @operands = @$operands if $operands;
my @operators = @$operators if $operators;
my @indexes = @$indexes if $indexes;
my @operands = @$operands if $operands;
$query_cgi =~ s/^&//;
# append the limit to the query
$query_cgi =~ s/^&//;
# append the limit to the query
+ $query ? $query .= " ".$limit : $query = $limit;
+ warn "query=$query and limit=$limit" if $DEBUG;
warn "QUERY:".$query if $DEBUG;
warn "QUERY CGI:".$query_cgi if $DEBUG;
warn "QUERY:".$query if $DEBUG;
warn "QUERY CGI:".$query_cgi if $DEBUG;
warn "LIMIT:".$limit if $DEBUG;
warn "LIMIT CGI:".$limit_cgi if $DEBUG;
warn "LIMIT DESC:".$limit_desc if $DEBUG;
warn "LIMIT:".$limit if $DEBUG;
warn "LIMIT CGI:".$limit_cgi if $DEBUG;
warn "LIMIT DESC:".$limit_desc if $DEBUG;
+ warn "---------" if $DEBUG;
+ warn "Leave buildQuery" if $DEBUG;
+ warn "---------" if $DEBUG;
return ( undef, $query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type );
}
return ( undef, $query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type );
}
=cut
sub NZgetRecords {
my ($query,$simple_query,$sort_by_ref,$servers_ref,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan) = @_;
=cut
sub NZgetRecords {
my ($query,$simple_query,$sort_by_ref,$servers_ref,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan) = @_;
+ warn "query =$query" if $DEBUG;
my $result = NZanalyse($query);
my $result = NZanalyse($query);
+ warn "results =$result" if $DEBUG;
return (undef,NZorder($result,@$sort_by_ref[0],$results_per_page,$offset),undef);
}
return (undef,NZorder($result,@$sort_by_ref[0],$results_per_page,$offset),undef);
}
sub NZanalyse {
my ($string,$server) = @_;
sub NZanalyse {
my ($string,$server) = @_;
+ warn "---------" if $DEBUG;
+ warn "Enter NZanalyse" if $DEBUG;
+ warn "---------" if $DEBUG;
+
# $server contains biblioserver or authorities, depending on what we search on.
#warn "querying : $string on $server";
$server='biblioserver' unless $server;
# $server contains biblioserver or authorities, depending on what we search on.
#warn "querying : $string on $server";
$server='biblioserver' unless $server;
#process parenthesis before.
if ($string =~ /^\s*\((.*)\)(( and | or | not | AND | OR | NOT )(.*))?/){
my $left = $1;
#process parenthesis before.
if ($string =~ /^\s*\((.*)\)(( and | or | not | AND | OR | NOT )(.*))?/){
my $left = $1;
my $right = $4;
my $operator = lc($3); # FIXME: and/or/not are operators, not operands
my $right = $4;
my $operator = lc($3); # FIXME: and/or/not are operators, not operands
+ warn "dealing w/parenthesis before recursive sub call. left :$left operator:$operator right:$right" if $DEBUG;
my $leftresult = NZanalyse($left,$server);
if ($operator) {
my $rightresult = NZanalyse($right,$server);
my $leftresult = NZanalyse($left,$server);
if ($operator) {
my $rightresult = NZanalyse($right,$server);
my $value=$_;
$value=$1 if $value=~m/(.*)-\d+$/;
unless ($rightresult =~ "$value-") {
my $value=$_;
$value=$1 if $value=~m/(.*)-\d+$/;
unless ($rightresult =~ "$value-") {
my $left = $1;
my $right = $3;
my $operator = lc($2); # FIXME: and/or/not are operators, not operands
my $left = $1;
my $right = $3;
my $operator = lc($2); # FIXME: and/or/not are operators, not operands
+ warn "dealing w/parenthesis. left :$left operator:$operator right:$right" if $DEBUG;
# it's not a leaf, we have a and/or/not
if ($operator) {
# reintroduce comma content if needed
# it's not a leaf, we have a and/or/not
if ($operator) {
# reintroduce comma content if needed
# it's a leaf, do the real SQL query and return the result
} else {
$string =~ s/__X__/"$commacontent"/ if $commacontent;
# it's a leaf, do the real SQL query and return the result
} else {
$string =~ s/__X__/"$commacontent"/ if $commacontent;
- $string =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|&|\+|\*|\// /g;
- warn "leaf : $string\n" if $DEBUG;
+ $string =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|&|\+|\*|\///g; # we must not introduce spaces in place of these chars
+ warn "leaf:$string" if $DEBUG;
# parse the string in in operator/operand/value again
$string =~ /(.*)(>=|<=)(.*)/;
my $left = $1;
my $operator = $2;
my $right = $3;
# parse the string in in operator/operand/value again
$string =~ /(.*)(>=|<=)(.*)/;
my $left = $1;
my $operator = $2;
my $right = $3;
+ warn "handling leaf... left:$left operator:$operator right:$right" if $DEBUG;
unless ($operator) {
$string =~ /(.*)(>|<|=)(.*)/;
$left = $1;
$operator = $2;
$right = $3;
unless ($operator) {
$string =~ /(.*)(>|<|=)(.*)/;
$left = $1;
$operator = $2;
$right = $3;
+ warn "handling unless (operator)... left:$left operator:$operator right:$right" if $DEBUG;
}
my $results;
# strip adv, zebra keywords, currently not handled in nozebra: wrdl, ext, phr...
}
my $results;
# strip adv, zebra keywords, currently not handled in nozebra: wrdl, ext, phr...
$left='subject' if $left =~ '^su$';
$left='koha-Auth-Number' if $left =~ '^an$';
$left='keyword' if $left =~ '^kw$';
$left='subject' if $left =~ '^su$';
$left='koha-Auth-Number' if $left =~ '^an$';
$left='keyword' if $left =~ '^kw$';
+ $left='itemtype' if $left =~ '^mc$'; # we must allow for limit operators since buildQuery will append $limit to $query
if ($operator && $left ne 'keyword' ) {
#do a specific search
my $dbh = C4::Context->dbh;
if ($operator && $left ne 'keyword' ) {
#do a specific search
my $dbh = C4::Context->dbh;
warn "return : $results for LEAF : $string" if $DEBUG;
return $results;
}
warn "return : $results for LEAF : $string" if $DEBUG;
return $results;
}
+ warn "---------" if $DEBUG;
+ warn "Leave NZanalyse" if $DEBUG;
+ warn "---------" if $DEBUG;