Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search: word1 word2 word3 to use AND-ing instead of OR-ing #3140

Closed
tiborsimko opened this issue Aug 11, 2021 · 3 comments · Fixed by #3482
Closed

search: word1 word2 word3 to use AND-ing instead of OR-ing #3140

tiborsimko opened this issue Aug 11, 2021 · 3 comments · Fixed by #3482
Assignees

Comments

@tiborsimko
Copy link
Member

Current behaviour

Search for cms event. You get 5040 hits including PHENIX record etc which are not what users would expect.

This is because searching for cms event is equivalent to searching for cms OR event, followed by appied ranking.

If you look for cms AND event, you get 1038 hits which are closer to what users expect. (I.e. no PHENIX record, etc).

Expected behaviour

When a user searches for word1 word2 word3, one would expect to do word1 AND word2 AND word3 query instead of current word1 OR word2 OR word3. The former is much more common in general search engines.

Let's change the behaviour to "silent AND" instead of "silent OR" for multi-word queries.

@psaiz psaiz self-assigned this Nov 30, 2023
@psaiz
Copy link
Contributor

psaiz commented Nov 30, 2023

Our inspire colleagues do already the AND. I like that behaviour much better.

@psaiz
Copy link
Contributor

psaiz commented Nov 30, 2023

This comes from the default parser. A change like:

--- a/invenio_records_rest/query.py
+++ b/invenio_records_rest/query.py
@@ -25,7 +25,7 @@ def default_search_factory(self, search, query_parser=None):
     def _default_parser(qstr=None):
         """Default parser that uses the Q() from search engine dsl."""
         if qstr:
-            return dsl.Q("query_string", query=qstr)
+            return dsl.Q("query_string", query=qstr, default_operator='AND')

would do the trick. I'll check with our invenio colleagues if this is worth a new parameter in records_rest, or if we shouldjust pass our parser.

@psaiz psaiz linked a pull request Dec 4, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants