diff --git a/CHANGELOG.md b/CHANGELOG.md index 27eff065a..73a129428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ -Tantivy 0.6 +Master (future Tantivy 0.7) ========================== +- Added support for parsing AllQuery and RangeQuery via QueryParser + - AllQuery: `*` + - RangeQuery: + - Inclusive `field:[startIncl to endIncl]` + - Exclusive `field:{startExcl to endExcl}` + - Mixed `field:[startIncl to endExcl}` and vice versa + - Unbounded `field:[start to *]`, `field:[* to end]` + +Tantivy 0.6 +========================== Special thanks to @drusellers and @jason-wolfe for their contributions to this release! diff --git a/Cargo.toml b/Cargo.toml index b85650c40..7b5208fc0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "tantivy" -version = "0.6.0" +name = "tantivy " +version = "0.7.0-dev" authors = ["Paul Masurel "] license = "MIT" categories = ["database-implementations", "data-structures"] diff --git a/src/query/query_parser/query_grammar.rs b/src/query/query_parser/query_grammar.rs index 29ad158df..3b9247a24 100644 --- a/src/query/query_parser/query_grammar.rs +++ b/src/query/query_parser/query_grammar.rs @@ -46,7 +46,9 @@ where } fn range>(input: I) -> ParseResult { - let term_val = || word().or(negative_number()); + let term_val = || { + word().or(negative_number()).or(char('*').map(|_| "*".to_string())) + }; let lower_bound = { let excl = (char('{'), term_val()).map(|(_, w)| UserInputBound::Exclusive(w)); let incl = (char('['), term_val()).map(|(_, w)| UserInputBound::Inclusive(w)); @@ -133,6 +135,8 @@ mod test { test_parse_query_to_ast_helper("[1 TO 5]", "[\"1\" TO \"5\"]"); test_parse_query_to_ast_helper("foo:{a TO z}", "foo:{\"a\" TO \"z\"}"); test_parse_query_to_ast_helper("foo:[1 TO toto}", "foo:[\"1\" TO \"toto\"}"); + test_parse_query_to_ast_helper("foo:[* TO toto}", "foo:[\"*\" TO \"toto\"}"); + test_parse_query_to_ast_helper("foo:[1 TO *}", "foo:[\"1\" TO \"*\"}"); test_is_parse_err("abc + "); } } diff --git a/src/query/query_parser/query_parser.rs b/src/query/query_parser/query_parser.rs index 43d11000f..dfe1d6dcf 100644 --- a/src/query/query_parser/query_parser.rs +++ b/src/query/query_parser/query_parser.rs @@ -271,11 +271,10 @@ impl QueryParser { } } - fn resolve_bound( - &self, - field: Field, - bound: &UserInputBound, - ) -> Result, QueryParserError> { + fn resolve_bound(&self, field: Field, bound: &UserInputBound) -> Result, QueryParserError> { + if bound.term_str() == "*" { + return Ok(Bound::Unbounded); + } let terms = self.compute_terms_for_string(field, bound.term_str())?; if terms.len() != 1 { return Err(QueryParserError::RangeMustNotHavePhrase); @@ -634,7 +633,22 @@ mod test { Excluded(Term([0, 0, 0, 0, 116, 111, 116, 111])))", false, ); - test_parse_query_to_logical_ast_helper("*", "*", false); + test_parse_query_to_logical_ast_helper( + "title:{* TO toto}", + "(Unbounded TO \ + Excluded(Term([0, 0, 0, 0, 116, 111, 116, 111])))", + false, + ); + test_parse_query_to_logical_ast_helper( + "title:{titi TO *}", + "(Excluded(Term([0, 0, 0, 0, 116, 105, 116, 105])) TO Unbounded)", + false, + ); + test_parse_query_to_logical_ast_helper( + "*", + "*", + false, + ); } #[test]