From a262c67ec3f8bc788ef583222af8c02f313065d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 8 Jan 2020 13:06:12 +0100 Subject: [PATCH] limit the search in the FST --- meilisearch-core/src/query_tree.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/meilisearch-core/src/query_tree.rs b/meilisearch-core/src/query_tree.rs index 5c26e1437..d3c549b03 100644 --- a/meilisearch-core/src/query_tree.rs +++ b/meilisearch-core/src/query_tree.rs @@ -326,20 +326,19 @@ pub fn traverse_query_tree<'o, 'txn>( { let before = Instant::now(); - // let byte = query.as_bytes()[0]; - // let mut stream = if byte == u8::max_value() { - // words.search(&dfa).ge(&[byte]).into_stream() - // } else { - // words.search(&dfa).ge(&[byte]).lt(&[byte + 1]).into_stream() - // }; - let Query { id, prefix, kind } = query; let docids = match kind { QueryKind::Tolerant(word) => { let dfa = if *prefix { build_prefix_dfa(word) } else { build_dfa(word) }; + let byte = word.as_bytes()[0]; + let mut stream = if byte == u8::max_value() { + words_set.search(&dfa).ge(&[byte]).into_stream() + } else { + words_set.search(&dfa).ge(&[byte]).lt(&[byte + 1]).into_stream() + }; + let mut docids = Vec::new(); - let mut stream = words_set.search(&dfa).into_stream(); while let Some(input) = stream.next() { if let Some(matches) = pls.postings_list(reader, input)? { docids.extend(matches.iter().map(|d| d.document_id)) @@ -352,8 +351,14 @@ pub fn traverse_query_tree<'o, 'txn>( // TODO support prefix and non-prefix exact DFA let dfa = build_exact_dfa(word); + let byte = word.as_bytes()[0]; + let mut stream = if byte == u8::max_value() { + words_set.search(&dfa).ge(&[byte]).into_stream() + } else { + words_set.search(&dfa).ge(&[byte]).lt(&[byte + 1]).into_stream() + }; + let mut docids = Vec::new(); - let mut stream = words_set.search(&dfa).into_stream(); while let Some(input) = stream.next() { if let Some(matches) = pls.postings_list(reader, input)? { docids.extend(matches.iter().map(|d| d.document_id))