From 6eb25687f8ad48d88dd429e96ca66d6f9712c2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 2 May 2019 12:10:54 +0200 Subject: [PATCH] feat: Handle word doc-indexes sled tree errors --- meilidb-core/src/query_builder.rs | 22 ++++++++++------------ meilidb/examples/query-database.rs | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/meilidb-core/src/query_builder.rs b/meilidb-core/src/query_builder.rs index 40e172403..b5ff3a530 100644 --- a/meilidb-core/src/query_builder.rs +++ b/meilidb-core/src/query_builder.rs @@ -86,7 +86,7 @@ impl<'c, I, FI, S> QueryBuilder<'c, I, FI> where I: Deref>, S: Store, { - fn query_all(&self, query: &str) -> Vec { + fn query_all(&self, query: &str) -> Result, S::Error> { let automatons = generate_automatons(query); let fst = self.index.set.as_fst(); @@ -107,10 +107,8 @@ where I: Deref>, let distance = automaton.eval(input).to_u8(); let is_exact = distance == 0 && input.len() == automaton.query_len(); - // let doc_indexes = &self.index.indexes; - // let doc_indexes = &doc_indexes[iv.value as usize]; - - let doc_indexes = self.index.store.get_indexes(input).unwrap().unwrap(); + let doc_indexes = self.index.store.get_indexes(input)?; + let doc_indexes = doc_indexes.expect("word doc-indexes not found"); for di in doc_indexes.as_slice() { if self.searchable_attrs.as_ref().map_or(true, |r| r.contains(&di.attribute)) { @@ -135,7 +133,7 @@ where I: Deref>, info!("{} total documents to classify", raw_documents.len()); info!("{} total matches to classify", total_matches); - raw_documents + Ok(raw_documents) } } @@ -144,7 +142,7 @@ where I: Deref>, FI: Fn(DocumentId) -> bool, S: Store, { - pub fn query(self, query: &str, range: Range) -> Vec { + pub fn query(self, query: &str, range: Range) -> Result, S::Error> { // We delegate the filter work to the distinct query builder, // specifying a distinct rule that has no effect. if self.filter.is_some() { @@ -153,7 +151,7 @@ where I: Deref>, } let start = Instant::now(); - let mut documents = self.query_all(query); + let mut documents = self.query_all(query)?; info!("query_all took {:.2?}", start.elapsed()); let mut groups = vec![documents.as_mut_slice()]; @@ -190,7 +188,7 @@ where I: Deref>, let offset = cmp::min(documents.len(), range.start); let iter = documents.into_iter().skip(offset).take(range.len()); - iter.map(|d| Document::from_raw(&d)).collect() + Ok(iter.map(|d| Document::from_raw(&d)).collect()) } } @@ -224,9 +222,9 @@ where I: Deref>, K: Hash + Eq, S: Store, { - pub fn query(self, query: &str, range: Range) -> Vec { + pub fn query(self, query: &str, range: Range) -> Result, S::Error> { let start = Instant::now(); - let mut documents = self.inner.query_all(query); + let mut documents = self.inner.query_all(query)?; info!("query_all took {:.2?}", start.elapsed()); let mut groups = vec![documents.as_mut_slice()]; @@ -324,6 +322,6 @@ where I: Deref>, } } - out_documents + Ok(out_documents) } } diff --git a/meilidb/examples/query-database.rs b/meilidb/examples/query-database.rs index 6b048cc5b..1be27dce1 100644 --- a/meilidb/examples/query-database.rs +++ b/meilidb/examples/query-database.rs @@ -161,7 +161,7 @@ fn main() -> Result<(), Box> { let start_total = Instant::now(); let builder = index.query_builder(); - let documents = builder.query(query, 0..opt.number_results); + let documents = builder.query(query, 0..opt.number_results)?; let mut retrieve_duration = Duration::default();