From 4d054e6541f695d1c61e64788b40e7f32fe8cf59 Mon Sep 17 00:00:00 2001 From: "ping.xia" Date: Thu, 7 Sep 2023 20:43:06 -0400 Subject: [PATCH] fmt fix --- src/query/automaton_weight.rs | 7 +++---- src/query/fuzzy_query.rs | 12 +++++++----- src/schema/term.rs | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/query/automaton_weight.rs b/src/query/automaton_weight.rs index a178d0f795..36be9a2c70 100644 --- a/src/query/automaton_weight.rs +++ b/src/query/automaton_weight.rs @@ -4,21 +4,20 @@ use std::sync::Arc; use common::BitSet; use tantivy_fst::Automaton; +use super::phrase_prefix_query::prefix_end; use crate::core::SegmentReader; use crate::query::{BitSetDocSet, ConstScorer, Explanation, Scorer, Weight}; use crate::schema::{Field, IndexRecordOption}; use crate::termdict::{TermDictionary, TermStreamer}; use crate::{DocId, Score, TantivyError}; -use super::phrase_prefix_query::prefix_end; - /// A weight struct for Fuzzy Term and Regex Queries pub struct AutomatonWeight { field: Field, automaton: Arc, // For JSON fields, the term dictionary include terms from all paths. - // We apply additional filtering based on the given JSON path, when searching within the term dictionary. - // This prevents terms from unrelated paths from matching the search criteria. + // We apply additional filtering based on the given JSON path, when searching within the term + // dictionary. This prevents terms from unrelated paths from matching the search criteria. json_path_bytes: Option>, } diff --git a/src/query/fuzzy_query.rs b/src/query/fuzzy_query.rs index face3afa16..eea0106900 100644 --- a/src/query/fuzzy_query.rs +++ b/src/query/fuzzy_query.rs @@ -137,7 +137,8 @@ impl FuzzyTermQuery { if let Some(json_path_type) = term_value.json_path_type() { if json_path_type != Type::Str { return Err(InvalidArgument(format!( - "The fuzzy term query requires a string path type for a json term. Found {:?}", + "The fuzzy term query requires a string path type for a json term. Found \ + {:?}", json_path_type ))); } @@ -159,12 +160,12 @@ impl FuzzyTermQuery { automaton_builder.build_dfa(term_text) }; - if let Some(json_path_bytes) = term_value.as_json_path_bytes() { - return Ok(AutomatonWeight::new_for_json_path( + if let Some(json_path_bytes) = term_value.json_path_bytes() { + Ok(AutomatonWeight::new_for_json_path( self.term.field(), DfaWrapper(automaton), json_path_bytes, - )); + )) } else { Ok(AutomatonWeight::new( self.term.field(), @@ -244,7 +245,8 @@ mod test { assert_eq!(top_docs[0].1.doc_id, 1, "Expected the second document"); } - // shall match the first document because Levenshtein distance is 1 (substitute 'o' with 'a') + // shall match the first document because Levenshtein distance is 1 (substitute 'o' with + // 'a') { let term = get_json_path_term("attributes.a:japon")?; diff --git a/src/schema/term.rs b/src/schema/term.rs index eb0e2c9cc4..2eb7749472 100644 --- a/src/schema/term.rs +++ b/src/schema/term.rs @@ -425,7 +425,7 @@ where B: AsRef<[u8]> /// Returns the json path bytes (including the JSON_END_OF_PATH byte) /// /// Returns `None` if the value is not JSON. - pub(crate) fn as_json_path_bytes(&self) -> Option<&[u8]> { + pub(crate) fn json_path_bytes(&self) -> Option<&[u8]> { if self.typ() != Type::Json { return None; } @@ -433,7 +433,7 @@ where B: AsRef<[u8]> let bytes = self.value_bytes(); let pos = bytes.iter().cloned().position(|b| b == JSON_END_OF_PATH)?; // split at pos + 1, so that json_path_bytes includes the JSON_END_OF_PATH byte. - let (json_path_bytes, _) = bytes.split_at(pos+1); + let (json_path_bytes, _) = bytes.split_at(pos + 1); Some(json_path_bytes) }