Skip to content

QueryParser: make empty-query behaviour configurable (set_empty_query_match_all) #2655

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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]

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.

1 participant