diff --git a/quickwit/quickwit-doc-mapper/src/query_builder.rs b/quickwit/quickwit-doc-mapper/src/query_builder.rs index dbc663794e5..fd1054ab850 100644 --- a/quickwit/quickwit-doc-mapper/src/query_builder.rs +++ b/quickwit/quickwit-doc-mapper/src/query_builder.rs @@ -248,7 +248,9 @@ impl<'a, 'b: 'a> QueryAstVisitor<'a> for ExtractPrefixTermRanges<'b> { ) -> Result<(), Self::Err> { let terms = match phrase_prefix.get_terms(self.schema, self.tokenizer_manager) { Ok((_, terms)) => terms, - Err(InvalidQuery::SchemaError(_)) => return Ok(()), /* the query will be nullified when casting to a tantivy ast */ + Err(InvalidQuery::SchemaError(_)) | Err(InvalidQuery::FieldDoesNotExist { .. }) => { + return Ok(()) + } /* the query will be nullified when casting to a tantivy ast */ Err(e) => return Err(e), }; if let Some((_, term)) = terms.last() { @@ -258,7 +260,12 @@ impl<'a, 'b: 'a> QueryAstVisitor<'a> for ExtractPrefixTermRanges<'b> { } fn visit_wildcard(&mut self, wildcard_query: &'a WildcardQuery) -> Result<(), Self::Err> { - let (_, term) = wildcard_query.extract_prefix_term(self.schema, self.tokenizer_manager)?; + let term = match wildcard_query.extract_prefix_term(self.schema, self.tokenizer_manager) { + Ok((_, term)) => term, + /* the query will be nullified when casting to a tantivy ast */ + Err(InvalidQuery::FieldDoesNotExist { .. }) => return Ok(()), + Err(e) => return Err(e), + }; self.add_prefix_term(term, u32::MAX, false); Ok(()) } diff --git a/quickwit/quickwit-query/src/elastic_query_dsl/phrase_prefix_query.rs b/quickwit/quickwit-query/src/elastic_query_dsl/phrase_prefix_query.rs index 3955a175c64..4579b6530bf 100644 --- a/quickwit/quickwit-query/src/elastic_query_dsl/phrase_prefix_query.rs +++ b/quickwit/quickwit-query/src/elastic_query_dsl/phrase_prefix_query.rs @@ -67,6 +67,7 @@ impl ConvertibleToQueryAst for MatchPhrasePrefixQuery { phrase: query, params: analyzer, max_expansions, + lenient: false, }; Ok(phrase_prefix_query_ast.into()) } diff --git a/quickwit/quickwit-query/src/query_ast/phrase_prefix_query.rs b/quickwit/quickwit-query/src/query_ast/phrase_prefix_query.rs index d0107f885f9..cf066f04c27 100644 --- a/quickwit/quickwit-query/src/query_ast/phrase_prefix_query.rs +++ b/quickwit/quickwit-query/src/query_ast/phrase_prefix_query.rs @@ -38,6 +38,7 @@ pub struct PhrasePrefixQuery { pub phrase: String, pub max_expansions: u32, pub params: FullTextParams, + pub lenient: bool, } impl PhrasePrefixQuery { @@ -117,7 +118,13 @@ impl BuildTantivyAst for PhrasePrefixQuery { _search_fields: &[String], _with_validation: bool, ) -> Result { - let (_, terms) = self.get_terms(schema, tokenizer_manager)?; + let (_, terms) = match self.get_terms(schema, tokenizer_manager) { + Ok(res) => res, + Err(InvalidQuery::FieldDoesNotExist { .. }) if self.lenient => { + return Ok(crate::MatchAllOrNone::MatchNone.into()) + } + Err(e) => return Err(e), + }; if terms.is_empty() { if self.params.zero_terms_query.is_none() { diff --git a/quickwit/quickwit-query/src/query_ast/user_input_query.rs b/quickwit/quickwit-query/src/query_ast/user_input_query.rs index 8a910567982..cebb5ed0adc 100644 --- a/quickwit/quickwit-query/src/query_ast/user_input_query.rs +++ b/quickwit/quickwit-query/src/query_ast/user_input_query.rs @@ -273,12 +273,14 @@ fn convert_user_input_literal( phrase: phrase.clone(), params: full_text_params.clone(), max_expansions: DEFAULT_PHRASE_QUERY_MAX_EXPANSION, + lenient, } .into() } else if wildcard { query_ast::WildcardQuery { field: field_name, value: phrase.clone(), + lenient, } .into() } else { diff --git a/quickwit/quickwit-query/src/query_ast/wildcard_query.rs b/quickwit/quickwit-query/src/query_ast/wildcard_query.rs index 86afb68a7d3..4bb24c4fd09 100644 --- a/quickwit/quickwit-query/src/query_ast/wildcard_query.rs +++ b/quickwit/quickwit-query/src/query_ast/wildcard_query.rs @@ -34,6 +34,7 @@ use crate::{find_field_or_hit_dynamic, InvalidQuery}; pub struct WildcardQuery { pub field: String, pub value: String, + pub lenient: bool, } impl From for QueryAst { @@ -190,7 +191,13 @@ impl BuildTantivyAst for WildcardQuery { _search_fields: &[String], _with_validation: bool, ) -> Result { - let (_, term) = self.extract_prefix_term(schema, tokenizer_manager)?; + let (_, term) = match self.extract_prefix_term(schema, tokenizer_manager) { + Ok(res) => res, + Err(InvalidQuery::FieldDoesNotExist { .. }) if self.lenient => { + return Ok(crate::MatchAllOrNone::MatchNone.into()) + } + Err(e) => return Err(e), + }; let mut phrase_prefix_query = tantivy::query::PhrasePrefixQuery::new_with_offset(vec![(0, term)]);