Skip to content

Conversation

MagellaX
Copy link

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

  1. New field empty_query_match_all: bool (default false) added to QueryParser.
    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]

…empty_query_match_all; keep default EmptyQuery; handle lenient parse errors (quickwit-oss#386)
Copy link
Collaborator

@fulmicoton fulmicoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but can you add unit tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants