Bug 33093: (Bug 27546 follow-up) With ES searching within results does not work for 'Keyword' and 'Keyword as phrase'

The feature of searching within search results in librarian
interface has some problems with with elastic: 'Keyword' and
'Keyword as phrase' searches give no results.  This is because
elastic is unaware of the search field 'kw' and 'kw' is not
transformed nor removed for limits.

Test plan
=========
1. Have a Koha instance with reasonable number of biblio records
1. Set SearchEngine to Elasticsearch
3. In librarian interface, perform a search that would give
   you a list of results
4. With the new search box 'Search within results', having 'Keyword'
   and 'Keyword as phrase' active, try to perform a search within
   search results with a term that should give you some results
5. You should get no results
6. Apply the patch
7. Repeat steps 3 and 4
8. You should get expected results.  Note the difference between
   'Keyword' and 'Keyword as phrase' in results
9. Sign off

Signed-off-by: Emmi Takkinen <emmi.takkinen@koha-suomi.fi>

Signed-off-by: Nick <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Janusz Kaczmarek 2023-02-28 19:18:05 +01:00 committed by Tomas Cohen Arazi
parent 2553dcef23
commit eb5cc8d708
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -1131,6 +1131,15 @@ sub _fix_limit_special_cases {
elsif ( $l =~ /^available$/ ) {
push @new_lim, 'available:true';
}
elsif ( $l =~ /^\s*(kw\b[\w,-]*?):(.*)/) {
my ( $field, $term ) = ($1, $2);
if ( defined($field) && defined($term) && $field =~ /,phr$/) {
push @new_lim, "(\"$term\")";
}
else {
push @new_lim, $term;
}
}
else {
my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/;
$field =~ s/,phr$//; #We are quoting all the limits as phrase, this prevents from quoting again later