From 795557c046110873f636327ec926249346d0c093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 15 Jul 2019 14:28:40 +0200 Subject: [PATCH] feat: Remove query splitting from the automaton generation --- meilidb-core/src/query_builder.rs | 88 +------------------------------ 1 file changed, 1 insertion(+), 87 deletions(-) diff --git a/meilidb-core/src/query_builder.rs b/meilidb-core/src/query_builder.rs index 5268edd27..1fb778094 100644 --- a/meilidb-core/src/query_builder.rs +++ b/meilidb-core/src/query_builder.rs @@ -65,29 +65,6 @@ pub fn normalize_str(string: &str) -> String { string } -fn split_best_frequency<'a, S: Store>( - word: &'a str, - store: &S, -) -> Result, S::Error> -{ - let chars = word.char_indices().skip(1); - let mut best = None; - - for (i, _) in chars { - let (left, right) = word.split_at(i); - - let left_freq = store.word_indexes(left.as_bytes())?.map_or(0, |i| i.len()); - let right_freq = store.word_indexes(right.as_bytes())?.map_or(0, |i| i.len()); - let min_freq = cmp::min(left_freq, right_freq); - - if min_freq != 0 && best.map_or(true, |(old, _, _)| min_freq > old) { - best = Some((min_freq, left, right)); - } - } - - Ok(best.map(|(_, l, r)| (l, r))) -} - fn generate_automatons(query: &str, store: &S) -> Result<(Vec, QueryEnhancer), S::Error> { let has_end_whitespace = query.chars().last().map_or(false, char::is_whitespace); let query_words: Vec<_> = split_query_string(query).map(str::to_lowercase).collect(); @@ -160,24 +137,7 @@ fn generate_automatons(query: &str, store: &S) -> Result<(Vec { - let mut matches = matches.into_iter(); - let mut highlights = highlights.into_iter(); - - assert_matches!(matches.next(), Some(TmpMatch { query_index: 0, word_index: 0, .. })); // porte - assert_matches!(highlights.next(), Some(Highlight { char_index: 0, .. })); - - assert_matches!(matches.next(), Some(TmpMatch { query_index: 1, word_index: 1, .. })); // feuille - assert_matches!(highlights.next(), Some(Highlight { char_index: 1, .. })); - - assert_matches!(matches.next(), None); - }); - assert_matches!(iter.next(), None); - - let builder = QueryBuilder::new(&store); - let results = builder.query("searchengine", 0..20).unwrap(); - let mut iter = results.into_iter(); - - assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches, highlights }) => { - let mut matches = matches.into_iter(); - let mut highlights = highlights.into_iter(); - - assert_matches!(matches.next(), Some(TmpMatch { query_index: 0, word_index: 0, .. })); // search - assert_matches!(highlights.next(), Some(Highlight { char_index: 0, .. })); - - assert_matches!(matches.next(), Some(TmpMatch { query_index: 1, word_index: 1, .. })); // engine - assert_matches!(highlights.next(), Some(Highlight { char_index: 1, .. })); - - assert_matches!(matches.next(), None); - }); - assert_matches!(iter.next(), None); - } }