Skip to content

Commit

Permalink
fmt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PingXia-at committed Sep 8, 2023
1 parent 1ef7da4 commit 4d054e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/query/automaton_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A> {
field: Field,
automaton: Arc<A>,
// 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<Box<[u8]>>,
}

Expand Down
12 changes: 7 additions & 5 deletions src/query/fuzzy_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)));
}
Expand All @@ -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(),
Expand Down Expand Up @@ -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")?;

Expand Down
4 changes: 2 additions & 2 deletions src/schema/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,15 @@ 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;
}

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)
}

Expand Down

0 comments on commit 4d054e6

Please sign in to comment.