From 79e0a6dd4e8fe6a8b0f5eb3f38cf24d444e10c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Lecrenier?= Date: Tue, 21 Feb 2023 09:41:58 +0100 Subject: [PATCH] Introduce a new search module, eventually meant to replace the old one The code here does not compile, because I am merely splitting one giant commit into smaller ones where each commit explains a single file. --- milli/src/search/new/mod.rs | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 milli/src/search/new/mod.rs diff --git a/milli/src/search/new/mod.rs b/milli/src/search/new/mod.rs new file mode 100644 index 000000000..17e74e70e --- /dev/null +++ b/milli/src/search/new/mod.rs @@ -0,0 +1,55 @@ +pub mod db_cache; +pub mod graph_based_ranking_rule; +pub mod query_graph; +pub mod query_term; +pub mod ranking_rule_graph; +pub mod ranking_rules; +pub mod resolve_query_graph; +pub mod sort; +pub mod words; + +use charabia::Tokenize; +use heed::RoTxn; +pub use query_graph::*; +pub use ranking_rules::*; +use roaring::RoaringBitmap; + +use self::{ + db_cache::DatabaseCache, + query_term::{word_derivations, LocatedQueryTerm}, +}; +use crate::{Index, Result}; + +pub enum BitmapOrAllRef<'s> { + Bitmap(&'s RoaringBitmap), + All, +} + +pub fn make_query_graph<'transaction>( + index: &Index, + txn: &RoTxn, + db_cache: &mut DatabaseCache<'transaction>, + query: &str, +) -> Result { + assert!(!query.is_empty()); + let fst = index.words_fst(txn).unwrap(); + let query = LocatedQueryTerm::from_query(query.tokenize(), None, |word, is_prefix| { + word_derivations( + index, + txn, + word, + if word.len() < 4 { + 0 + } else if word.len() < 100 { + 1 + } else { + 2 + }, + is_prefix, + &fst, + ) + }) + .unwrap(); + let graph = QueryGraph::from_query(index, txn, db_cache, query)?; + Ok(graph) +}