Bug 33093

Summary: (Bug 27546 follow-up) With ES searching within results does not work for 'Keyword' and 'Keyword as phrase'
Product: Koha Reporter: Janusz Kaczmarek <januszop>
Component: SearchingAssignee: Janusz Kaczmarek <januszop>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: normal    
Priority: P3 CC: emily.lamancusa, emmi.takkinen, fridolin.somers, lucas, nick
Version: 22.11   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00,22.11.06
Circulation function:
Bug Depends on: 27546    
Bug Blocks:    
Attachments: Bug 33093 - (Bug 27546 follow-up) With ES searching within results does not work for 'Keyword' and 'Keyword as phrase'
Bug 33093 - (Bug 27546 follow-up) With ES searching within results does not work for 'Keyword' and 'Keyword as phrase'
Bug 33093 - (Bug 27546 follow-up) With ES searching within results does not work for 'Keyword' and 'Keyword as phrase'
Bug 33093: (Bug 27546 follow-up) With ES searching within results does not work for 'Keyword' and 'Keyword as phrase'

Description Janusz Kaczmarek 2023-02-28 18:17:30 UTC
The new feature of searching within search results in librarian interface (Bug 27546) works well with zebra but there are some problems with elastic: 'Keyword' and 'Keyword as phrase' give no results.  This is because elastic is unaware of the search field 'kw' and 'kw' is not transformed nor removed for limits.

A patch proposal will follow.
Comment 1 Janusz Kaczmarek 2023-02-28 19:29:00 UTC
Created attachment 147519 [details] [review]
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
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
Comment 2 Janusz Kaczmarek 2023-02-28 19:56:53 UTC
Created attachment 147520 [details] [review]
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
Comment 3 Emmi Takkinen 2023-03-31 09:38:11 UTC
Created attachment 149021 [details] [review]
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>
Comment 4 Nick Clemens (kidclamp) 2023-04-17 19:02:36 UTC
*** Bug 33543 has been marked as a duplicate of this bug. ***
Comment 5 Nick Clemens (kidclamp) 2023-04-17 19:06:31 UTC
Created attachment 149771 [details] [review]
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>
Comment 6 Nick Clemens (kidclamp) 2023-04-17 19:09:27 UTC
This fixes the bug, it also improves handling of phrasing for keyword search - title and other limits are all quoted by default - which looks intentional, but this works as expected. I think we should open a follow-up to address limit phrasing at large and possible consolidate code - bug 33548
Comment 7 Tomás Cohen Arazi (tcohen) 2023-05-09 13:51:38 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 8 Matt Blenkinsop 2023-05-15 10:09:59 UTC
Nice work everyone!

Pushed to stable for 22.11.x
Comment 9 Fridolin Somers 2023-05-15 19:49:16 UTC
We should add a unit test to :
t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t
Comment 10 Lucas Gass (lukeg) 2023-06-15 15:00:31 UTC
Missing dependencies for 22.05.x, no backport.