From 7541ab99cdcc0f60fd92895f697a7e628d983b58 Mon Sep 17 00:00:00 2001 From: mpostma Date: Tue, 25 Jan 2022 10:06:27 +0100 Subject: [PATCH] review changes --- Cargo.toml | 3 --- milli/src/search/mod.rs | 18 ++++++------------ milli/src/search/query_tree.rs | 2 -- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9b97dee88..6b3e12f07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,3 @@ opt-level = 3 opt-level = 3 [profile.test.build-override] opt-level = 3 - -[patch.crates-io] -fst = { path = "/Users/mpostma/Documents/code/rust/fst/" } diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index cf596fa7a..67b86d6bf 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -294,24 +294,18 @@ pub fn word_derivations<'c>( let word = std::str::from_utf8(word)?; derived_words.push((word.to_string(), 0)); } - } else { - let automaton = Str::new(word); - let mut stream = fst.search(automaton).into_stream(); - while let Some(word) = stream.next() { - let word = std::str::from_utf8(word)?; - derived_words.push((word.to_string(), 0)); - } + } else if fst.contains(word) { + derived_words.push((word.to_string(), 0)); } } else { if max_typo == 1 { let dfa = build_dfa(word, 1, is_prefix); let starts = Str::new(get_first(word)).starts_with(); - let mut stream = fst.search_with_state(starts.intersection(&dfa)).into_stream(); + let mut stream = fst.search(starts.intersection(&dfa)).into_stream(); - while let Some((word, state)) = stream.next() { + while let Some(word) = stream.next() { let word = std::str::from_utf8(word)?; - let distance = dfa.distance(state.1); - derived_words.push((word.to_string(), distance.to_u8())); + derived_words.push((word.to_string(), 1)); } } else { let starts = Str::new(get_first(word)).starts_with(); @@ -335,7 +329,7 @@ pub fn word_derivations<'c>( fn get_first(s: &str) -> &str { match s.chars().next() { Some(c) => &s[..c.len_utf8()], - None => s, + None => panic!("unexpected empty query"), } } diff --git a/milli/src/search/query_tree.rs b/milli/src/search/query_tree.rs index d4cc338c8..355e42663 100644 --- a/milli/src/search/query_tree.rs +++ b/milli/src/search/query_tree.rs @@ -366,8 +366,6 @@ fn create_query_tree( let mut operations = synonyms(ctx, &words)?.unwrap_or_default(); let concat = words.concat(); let query = Query { prefix: is_prefix, kind: typos(concat, true, 1) }; - // let query = - // Query { prefix: is_prefix, kind: typos(concat, authorize_typos) }; operations.push(Operation::Query(query)); and_op_children.push(Operation::or(false, operations)); }