From 03f342aa67034a56876b9b45545c607b961587b7 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Tue, 6 Aug 2013 00:48:20 -0400 Subject: [PATCH] Bug 10688: Don't prefix index inappropriately If you select an index in the search dropdown and then enter in a QP query starting with the field, Koha will prepend the index you do not want to use at the beginning of the search, resulting in a search that probably does not match what you were hoping for. To test: 1) Select an index in the search dropdown in the OPAC. Author is fine. 2) Enter a search term using manually entered indexes. For example: ti:cat in the hat 3) Note that the search fails. 4) Apply patch. 5) Repeat steps 1 and 2. 6) Note that the search succeeds. 7) Sign off. Signed-off-by: Chris Cormack Signed-off-by: Jonathan Druart Signed-off-by: Galen Charlton --- C4/Search.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index dd844e389d..120fea1827 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1188,7 +1188,10 @@ sub parseQuery { next unless $operands[$ii]; $query .= $operators[ $ii - 1 ] eq 'or' ? ' || ' : ' && ' if ($query); - if ( $indexes[$ii] =~ m/su-/ ) { + if ( $operands[$ii] =~ /^[^"]\W*[-|_\w]*:\w.*[^"]$/ ) { + $query .= $operands[$ii]; + } + elsif ( $indexes[$ii] =~ m/su-/ ) { $query .= $indexes[$ii] . '(' . $operands[$ii] . ')'; } else { @@ -1281,7 +1284,7 @@ sub buildQuery { my $cclq = 0; my $cclindexes = getIndexes(); - if ( $query !~ /\s*ccl=/ ) { + if ( $query !~ /\s*(ccl=|pqf=|cql=)/ ) { while ( !$cclq && $query =~ /(?:^|\W)([\w-]+)(,[\w-]+)*[:=]/g ) { my $dx = lc($1); $cclq = grep { lc($_) eq $dx } @$cclindexes; -- 2.39.5