QueryParser: make empty-query behaviour configurable (set_empty_query_match_all)#2655
Open
MagellaX wants to merge 5 commits intoquickwit-oss:mainfrom
Open
QueryParser: make empty-query behaviour configurable (set_empty_query_match_all)#2655MagellaX wants to merge 5 commits intoquickwit-oss:mainfrom
MagellaX wants to merge 5 commits intoquickwit-oss:mainfrom
Conversation
fulmicoton
reviewed
Aug 11, 2025
…empty_query_match_all; keep default EmptyQuery; handle lenient parse errors (quickwit-oss#386)
fulmicoton
reviewed
Sep 3, 2025
fulmicoton
reviewed
Sep 3, 2025
fulmicoton
requested changes
Sep 3, 2025
Collaborator
fulmicoton
left a comment
There was a problem hiding this comment.
LGTM but can you add unit tests?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
an empty user query ("", whitespace-only, or a string that tokenises to nothing) is always translated into EmptyQuery, which matches no documents.
Issue #386 requests making this behaviour configurable because analytics dashboards and “show everything” listings often prefer an empty search box to return all documents.
What’s in this PR
API additions
set_empty_query_match_all(should_match_all: bool) – opt-in/out.
get_empty_query_match_all() -> bool – read current setting.
Centralised conversion – new helper logical_ast_to_query ensures the flag is respected by all parse_* and build_* entry points.
If the parsed AST is empty -> returns
AllQuery when the flag is true.
EmptyQuery (unchanged legacy behaviour) when false.
No breaking changes – the default remains “match nothing”; all existing tests continue to pass.
Docs – inline rustdoc comments explain the new behaviour.
Usage example
-------------```rust
let mut query_parser = QueryParser::for_index(&index, default_fields);
// Opt-in so that an empty search matches everything.
query_parser.set_empty_query_match_all(true);
// "" now yields AllQuery instead of EmptyQuery
let query = query_parser.parse_query("").unwrap();
assert_eq!(format!("{query:?}"), "AllQuery");
Impact
• Allows downstream applications to implement a “show all” behaviour without post-processing.
• Does not affect existing users unless they explicitly enable it.
Closes [#386]