Bug 27088 - Searching with just OR or AND gives error
Summary: Searching with just OR or AND gives error
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching - Elasticsearch (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor (vote)
Assignee: Bugs List
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-24 17:42 UTC by Joonas Kylmälä
Modified: 2020-12-03 01:57 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joonas Kylmälä 2020-11-24 17:42:28 UTC
If you search in intranet with elasticsearch just the string

> OR

or 

> AND

Then Koha gives error:

> Error: Unable to perform your search. Please try again. 

What I was expecting: no results found.
Comment 1 Jonathan Druart 2020-12-01 10:19:14 UTC
I am seeing:

/cgi-bin/koha/catalogue/search.pl?q=OR
No results found

No results match your search for 'kw,wrdl: OR'. 


/cgi-bin/koha/catalogue/search.pl?q=AND
No results found

No results match your search for 'kw,wrdl: AND'.
Comment 2 Joonas Kylmälä 2020-12-01 10:37:07 UTC
(In reply to Jonathan Druart from comment #1)
> I am seeing:
> 
> /cgi-bin/koha/catalogue/search.pl?q=OR
> No results found

Which Elasticsearch version you are using and are you using koha-testing-docker? I created the koha-testing-docker with

> docker-compose -f docker-compose.yml -f docker-compose.mariadb_latest.yml -f docker-compose.es6.yml -p koha up --force-recreate

and then run 

> koha-elasticsearch --rebuild -d kohadev

and then in systempreferences I changed searchengine to Elasticsearch.

After that doing the AND or OR search it gives error.
Comment 3 Jonathan Druart 2020-12-01 11:50:52 UTC
Sorry, something wrong on my side, Zebra was set (I am not used to check that, I setup my ktd with ES).
I do recreate the problem.
Comment 4 Jonathan Druart 2020-12-01 13:02:35 UTC
IMO we should keep this behaviour. The query has not a correct syntax and so it makes more sense to tell the user that there was an error than no results were found.
Comment 5 Joonas Kylmälä 2020-12-01 13:11:53 UTC
(In reply to Jonathan Druart from comment #4)
> IMO we should keep this behaviour. The query has not a correct syntax and so
> it makes more sense to tell the user that there was an error than no results
> were found.

In that case we should treat this as invalid query and notify the user along the lines "The search cannot be processed because of invalid usage of OR/AND." and don't don't even send the query to Elasticsearch. Now there is unhandled error coming from Elasticsearch which makes it then impossible to spot real system errors.

This bug can also be triggered with "something OR". With this "something OR" case it might be more desirable to just search for "something" or then convert OR to lower case and search for "something or" ?
Comment 6 Jonathan Druart 2020-12-01 13:36:44 UTC
IMO it's not a good idea to parse the query for such problems before we sent it to ES. We should request ES and eventually provide feedback to the user about why their query might have been syntactically wrong.
Comment 7 David Cook 2020-12-02 01:18:59 UTC
(In reply to Jonathan Druart from comment #6)
> IMO it's not a good idea to parse the query for such problems before we sent
> it to ES. We should request ES and eventually provide feedback to the user
> about why their query might have been syntactically wrong.

Agreed. Putting too much query parsing into Koha has gotten us into trouble in the past.
Comment 8 David Cook 2020-12-03 01:57:30 UTC
(In reply to Jonathan Druart from comment #6)
> IMO it's not a good idea to parse the query for such problems before we sent
> it to ES. We should request ES and eventually provide feedback to the user
> about why their query might have been syntactically wrong.

I'm sure it's probably a duplicate but I've raised Bug 27139 about showing users that there has been a search query error.

That being said... you can type gibberish into Google and Google will never tell you that you have a syntax error.

(Although I just tried doing an "any of these words" advanced search in Google using  "miniature OR" and it created a search query for "miniature OR OR" so even Google is a bit buggy / incorrectly documented when it comes to complex search.)

(Typing '"urban keith" and "pickles"' into Google without the single quotes also gives different results to what I'd expect. I want to know about Urban Keith and not Keith Urban, although it seems that Google thinks I've made a typo.)