Bug 31213

Summary: When performing a basic search with no results, repeat the search with term quoted
Product: Koha Reporter: Nick Clemens <nick>
Component: SearchingAssignee: Nick Clemens <nick>
Status: RESOLVED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: andrewfh, caroline.cyr-la-rose, dcook, fridolin.somers, joonas.kylmala, katrin.fischer, lucas, martin.renvoize, sally.healey, victor
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=1091
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33406
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
This enhancement adds a second, automatic, search with the search terms between quotation marks when a search returns no results. For example, searches with special characters don't work with Elasticsearch. A search for Ivy + Bean will return no results. But a search for "Ivy + Bean" will return results. With this enhancement, if a user searches for Ivy + Bean without quotation marks and gets no results, Koha will automatically search for "Ivy + Bean" and return those results. This targets both Zebra and Elasticsearch, but is more relevant for Elasticsearch.
Version(s) released in:
22.11.00,22.05.05,21.11.12
Bug Depends on:    
Bug Blocks: 32100    
Attachments: Bug 31213: Auto search simple term quoted
Bug 31213: Auto search simple term quoted
Bug 31213: Auto search simple term quoted

Description Nick Clemens 2022-07-21 18:16:12 UTC
Under elastic, when searching for some special characters a search may fail:
Ivy + Bean
The 6:20 man
etc.

These terms work when quoted:
"Ivy + Bean"

It would be nice if we just tried this automatically for the user
Comment 1 Nick Clemens 2022-07-21 18:19:56 UTC
Created attachment 137993 [details] [review]
Bug 31213: Auto search simple term quoted

This patch does a second search if the first had no results and was a simple single term search

We simply quote the term, rebuild the query, and rerun the search

This targets both Zebra and ES, but is more relevant for ES

To test:
0 - Have Koha running using ES
1 - Add titles your system "Ivy + Bean" "The 6:20 Man"
2 - Search for these titles without quotes - NO results under ES
3 - Search with quotes - you find them
4 - Apply patch, restart all
5 - Search again without quotes
6 - Success!
7 - Confirm search still works under Zebra
Comment 2 ByWater Sandboxes 2022-07-22 08:13:58 UTC
Created attachment 138002 [details] [review]
Bug 31213: Auto search simple term quoted

This patch does a second search if the first had no results and was a simple single term search

We simply quote the term, rebuild the query, and rerun the search

This targets both Zebra and ES, but is more relevant for ES

To test:
0 - Have Koha running using ES
1 - Add titles your system "Ivy + Bean" "The 6:20 Man"
2 - Search for these titles without quotes - NO results under ES
3 - Search with quotes - you find them
4 - Apply patch, restart all
5 - Search again without quotes
6 - Success!
7 - Confirm search still works under Zebra

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 3 Sally 2022-07-22 08:14:25 UTC
Works great, thanks Nick - signed off.
Comment 4 Martin Renvoize 2022-07-22 08:27:30 UTC
Great idea
Comment 5 Martin Renvoize 2022-07-22 08:30:10 UTC
Created attachment 138004 [details] [review]
Bug 31213: Auto search simple term quoted

This patch does a second search if the first had no results and was a simple single term search

We simply quote the term, rebuild the query, and rerun the search

This targets both Zebra and ES, but is more relevant for ES

To test:
0 - Have Koha running using ES
1 - Add titles your system "Ivy + Bean" "The 6:20 Man"
2 - Search for these titles without quotes - NO results under ES
3 - Search with quotes - you find them
4 - Apply patch, restart all
5 - Search again without quotes
6 - Success!
7 - Confirm search still works under Zebra

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 6 Martin Renvoize 2022-07-22 08:31:05 UTC
Works as described and the QA scripts are happy..

I wondered if we could possibly move it up a level into the modules but decided that's either a silly idea, or something for a future piece..

Passing QA
Comment 7 Katrin Fischer 2022-07-22 08:31:57 UTC
+1 from me as well.
Comment 8 Tomás Cohen Arazi 2022-07-22 15:29:48 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 9 David Cook 2022-08-22 06:41:22 UTC
This sounds so hacky but if it works...
Comment 10 Katrin Fischer 2022-08-22 07:45:58 UTC
(In reply to David Cook from comment #9)
> This sounds so hacky but if it works...

We often have libraries with callnumbers containing special characters (most of our libraries use custom classifications) like ( ) [] etc. that make an unquoted search return nothing. So I think this will prove helpful. 

Quoting right away would take the ability to truncate etc. away, but as a second step it makes sense.
Comment 11 David Cook 2022-08-22 23:38:58 UTC
(In reply to Katrin Fischer from comment #10)
> (In reply to David Cook from comment #9)
> > This sounds so hacky but if it works...
> 
> We often have libraries with callnumbers containing special characters (most
> of our libraries use custom classifications) like ( ) [] etc. that make an
> unquoted search return nothing. So I think this will prove helpful. 
> 
> Quoting right away would take the ability to truncate etc. away, but as a
> second step it makes sense.

I'm happy to agree to disagree when it comes to search :)
Comment 12 Lucas Gass 2022-09-02 15:04:29 UTC
Backported to 22.05.x for 22.05.05
Comment 13 Arthur Suzuki 2022-09-14 12:59:34 UTC
Thanks!

Pushed to 21.11 for 21.11.12
Comment 14 Victor Grousset/tuxayo 2022-09-19 21:05:48 UTC
Not backported to oldoldstable (21.05.x). Feel free to ask if it's needed.
Comment 15 Fridolin Somers 2022-10-04 07:02:01 UTC
This is super great :D
Comment 16 Caroline Cyr La Rose 2023-05-09 16:29:02 UTC
This seems like a backend change. There is no effect on the manual, that I can see.