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

allow term starting with wildcard in query parser #2568

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
improve handling of spcial char after exist query
trinity-1686a committed Jan 22, 2025
commit 5cea16ef9fe31d1cb2ed721fed10837343d38c0e
30 changes: 26 additions & 4 deletions query-grammar/src/query_grammar.rs
Original file line number Diff line number Diff line change
@@ -321,7 +321,17 @@ fn exists(inp: &str) -> IResult<&str, UserInputLeaf> {
UserInputLeaf::Exists {
field: String::new(),
},
tuple((multispace0, char('*'), peek(alt((multispace1, eof))))),
tuple((
multispace0,
char('*'),
peek(alt((
value(
"",
satisfy(|c: char| c.is_whitespace() || ESCAPE_IN_WORD.contains(&c)),
),
eof,
))),
)),
)(inp)
}

@@ -332,7 +342,13 @@ fn exists_precond(inp: &str) -> IResult<&str, (), ()> {
field_name,
multispace0,
char('*'),
peek(alt((multispace1, eof))), // we need to check this isn't a wildcard query
peek(alt((
value(
"",
satisfy(|c: char| c.is_whitespace() || ESCAPE_IN_WORD.contains(&c)),
),
eof,
))), // we need to check this isn't a wildcard query
))),
)(inp)
.map_err(|e| e.map(|_| ()))
@@ -1625,8 +1641,14 @@ mod test {

#[test]
fn test_exist_query() {
test_parse_query_to_ast_helper("a:*", "\"a\":*");
test_parse_query_to_ast_helper("a: *", "\"a\":*");
test_parse_query_to_ast_helper("a:*", "$exists(\"a\")");
test_parse_query_to_ast_helper("a: *", "$exists(\"a\")");

test_parse_query_to_ast_helper(
"(hello AND toto:*) OR happy",
"(?(+hello +$exists(\"toto\")) ?happy)",
);
test_parse_query_to_ast_helper("(a:*)", "$exists(\"a\")");

// these are term/wildcard query (not a phrase prefix)
test_parse_query_to_ast_helper("a:b*", "\"a\":b*");
2 changes: 1 addition & 1 deletion query-grammar/src/user_input_ast.rs
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ impl Debug for UserInputLeaf {
}
UserInputLeaf::All => write!(formatter, "*"),
UserInputLeaf::Exists { field } => {
write!(formatter, "\"{field}\":*")
write!(formatter, "$exists(\"{field}\")")
}
}
}

Unchanged files with check annotations Beta

#[test]
fn test_writer_options_validation() {
let mut schema_builder = Schema::builder();
let field = schema_builder.add_bool_field("example", STORED);

Check warning on line 2556 in src/indexer/index_writer.rs

GitHub Actions / clippy

unused variable: `field`

warning: unused variable: `field` --> src/indexer/index_writer.rs:2556:13 | 2556 | let field = schema_builder.add_bool_field("example", STORED); | ^^^^^ help: if this is intentional, prefix it with an underscore: `_field` | = note: `#[warn(unused_variables)]` on by default
let index = Index::create_in_ram(schema_builder.build());
let opt_wo_threads = IndexWriterOptions::builder().num_worker_threads(0).build();