Skip to content

Commit

Permalink
Initial fix suggestion from Trinity
Browse files Browse the repository at this point in the history
  • Loading branch information
rdettai committed Dec 9, 2024
1 parent 4756b8e commit 2951107
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
11 changes: 9 additions & 2 deletions quickwit/quickwit-doc-mapper/src/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl ConvertibleToQueryAst for MatchPhrasePrefixQuery {
phrase: query,
params: analyzer,
max_expansions,
lenient: false,
};
Ok(phrase_prefix_query_ast.into())
}
Expand Down
9 changes: 8 additions & 1 deletion quickwit/quickwit-query/src/query_ast/phrase_prefix_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct PhrasePrefixQuery {
pub phrase: String,
pub max_expansions: u32,
pub params: FullTextParams,
pub lenient: bool,
}

impl PhrasePrefixQuery {
Expand Down Expand Up @@ -117,7 +118,13 @@ impl BuildTantivyAst for PhrasePrefixQuery {
_search_fields: &[String],
_with_validation: bool,
) -> Result<TantivyQueryAst, InvalidQuery> {
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() {
Expand Down
2 changes: 2 additions & 0 deletions quickwit/quickwit-query/src/query_ast/user_input_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion quickwit/quickwit-query/src/query_ast/wildcard_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WildcardQuery> for QueryAst {
Expand Down Expand Up @@ -190,7 +191,13 @@ impl BuildTantivyAst for WildcardQuery {
_search_fields: &[String],
_with_validation: bool,
) -> Result<TantivyQueryAst, InvalidQuery> {
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)]);
Expand Down

0 comments on commit 2951107

Please sign in to comment.