From 8afd53e33349590366cfe8e35469d74a9654cb36 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Fri, 30 Nov 2007 10:14:11 -0600 Subject: [PATCH] Bug fixing : infinite loop when repeated operator + distinguishing operators limits would provide with unnecessary repeated "and" Thus causing wild loop So removing them. aud was transformed into author when it qualified audience. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Search.pm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index e19e3dc5f1..c42ca1d84f 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1181,10 +1181,13 @@ sub NZanalyse { # split the query string in 3 parts : X AND Y means : $left="X", $operand="AND" and $right="Y" # then, call again NZanalyse with $left and $right # (recursive until we find a leaf (=> something without and/or/not) + # delete repeated operator... Would then go in infinite loop + while ($string =~s/( and| or| not| AND| OR| NOT)\1/$1/g){ + } #process parenthesis before. if ($string =~ /^\s*\((.*)\)(( and | or | not | AND | OR | NOT )(.*))?/){ my $left = $1; - warn "left :".$left; +# warn "left :".$left; my $right = $4; my $operator = lc($3); # FIXME: and/or/not are operators, not operands my $leftresult = NZanalyse($left,$server); @@ -1227,7 +1230,7 @@ sub NZanalyse { } } } - warn "string :".$string; + warn "string :".$string if $DEBUG; $string =~ /(.*?)( and | or | not | AND | OR | NOT )(.*)/; my $left = $1; my $right = $3; @@ -1292,12 +1295,12 @@ sub NZanalyse { } my $results; # automatic replace for short operators - $left='title' if $left =~ '^ti'; - $left='author' if $left =~ '^au'; - $left='publisher' if $left =~ '^pb'; - $left='subject' if $left =~ '^su'; - $left='koha-Auth-Number' if $left =~ '^an'; - $left='keyword' if $left =~ '^kw'; + $left='title' if $left =~ '^ti$'; + $left='author' if $left =~ '^au$'; + $left='publisher' if $left =~ '^pb$'; + $left='subject' if $left =~ '^su$'; + $left='koha-Auth-Number' if $left =~ '^an$'; + $left='keyword' if $left =~ '^kw$'; if ($operator) { #do a specific search my $dbh = C4::Context->dbh; -- 2.39.5