From 2cc4a467a6db6012225c090ad1a8350d2f72fba4 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 3 Mar 2021 18:16:13 +0100 Subject: [PATCH] Change the criterion output that cannot fail --- milli/src/search/criteria/mod.rs | 12 ++++++------ milli/src/search/criteria/proximity.rs | 16 ++++++---------- milli/src/search/criteria/typo.rs | 24 ++++++++++-------------- milli/src/search/criteria/words.rs | 16 ++++++---------- 4 files changed, 28 insertions(+), 40 deletions(-) diff --git a/milli/src/search/criteria/mod.rs b/milli/src/search/criteria/mod.rs index 49bacf209..0dcaa5a69 100644 --- a/milli/src/search/criteria/mod.rs +++ b/milli/src/search/criteria/mod.rs @@ -138,9 +138,9 @@ impl<'t> CriteriaBuilder<'t> { for name in self.index.criteria(&self.rtxn)? { criterion = Some(match criterion.take() { Some(father) => match name { - Name::Typo => Box::new(Typo::new(self, father)?), - Name::Words => Box::new(Words::new(self, father)?), - Name::Proximity => Box::new(Proximity::new(self, father)?), + Name::Typo => Box::new(Typo::new(self, father)), + Name::Words => Box::new(Words::new(self, father)), + Name::Proximity => Box::new(Proximity::new(self, father)), Name::Asc(field) => { let (id, facet_type) = field_id_facet_type(&field)?; Box::new(AscDesc::asc(&self.index, &self.rtxn, father, id, facet_type)?) @@ -152,9 +152,9 @@ impl<'t> CriteriaBuilder<'t> { _otherwise => father, }, None => match name { - Name::Typo => Box::new(Typo::initial(self, query_tree.take(), facet_candidates.take())?), - Name::Words => Box::new(Words::initial(self, query_tree.take(), facet_candidates.take())?), - Name::Proximity => Box::new(Proximity::initial(self, query_tree.take(), facet_candidates.take())?), + Name::Typo => Box::new(Typo::initial(self, query_tree.take(), facet_candidates.take())), + Name::Words => Box::new(Words::initial(self, query_tree.take(), facet_candidates.take())), + Name::Proximity => Box::new(Proximity::initial(self, query_tree.take(), facet_candidates.take())), Name::Asc(field) => { let (id, facet_type) = field_id_facet_type(&field)?; Box::new(AscDesc::initial_asc(&self.index, &self.rtxn, query_tree.take(), facet_candidates.take(), id, facet_type)?) diff --git a/milli/src/search/criteria/proximity.rs b/milli/src/search/criteria/proximity.rs index fe82523ca..b192902c1 100644 --- a/milli/src/search/criteria/proximity.rs +++ b/milli/src/search/criteria/proximity.rs @@ -22,9 +22,9 @@ impl<'t> Proximity<'t> { ctx: &'t dyn Context, query_tree: Option, candidates: Option, - ) -> anyhow::Result + ) -> Self { - Ok(Proximity { + Proximity { ctx, query_tree: query_tree.map(|op| (maximum_proximity(&op), op)), proximity: 0, @@ -32,15 +32,11 @@ impl<'t> Proximity<'t> { bucket_candidates: RoaringBitmap::new(), parent: None, candidates_cache: HashMap::new(), - }) + } } - pub fn new( - ctx: &'t dyn Context, - parent: Box, - ) -> anyhow::Result - { - Ok(Proximity { + pub fn new(ctx: &'t dyn Context, parent: Box) -> Self { + Proximity { ctx, query_tree: None, proximity: 0, @@ -48,7 +44,7 @@ impl<'t> Proximity<'t> { bucket_candidates: RoaringBitmap::new(), parent: Some(parent), candidates_cache: HashMap::new(), - }) + } } } diff --git a/milli/src/search/criteria/typo.rs b/milli/src/search/criteria/typo.rs index 76c2fbc46..e952bda55 100644 --- a/milli/src/search/criteria/typo.rs +++ b/milli/src/search/criteria/typo.rs @@ -24,9 +24,9 @@ impl<'t> Typo<'t> { ctx: &'t dyn Context, query_tree: Option, candidates: Option, - ) -> anyhow::Result + ) -> Self { - Ok(Typo { + Typo { ctx, query_tree: query_tree.map(|op| (maximum_typo(&op), op)), number_typos: 0, @@ -35,15 +35,11 @@ impl<'t> Typo<'t> { parent: None, candidates_cache: HashMap::new(), typo_cache: HashMap::new(), - }) + } } - pub fn new( - ctx: &'t dyn Context, - parent: Box, - ) -> anyhow::Result - { - Ok(Typo { + pub fn new(ctx: &'t dyn Context, parent: Box) -> Self { + Typo { ctx, query_tree: None, number_typos: 0, @@ -52,7 +48,7 @@ impl<'t> Typo<'t> { parent: Some(parent), candidates_cache: HashMap::new(), typo_cache: HashMap::new(), - }) + } } } @@ -348,7 +344,7 @@ mod test { let query_tree = None; let facet_candidates = None; - let mut criteria = Typo::initial(&context, query_tree, facet_candidates).unwrap(); + let mut criteria = Typo::initial(&context, query_tree, facet_candidates); assert!(criteria.next().unwrap().is_none()); } @@ -366,7 +362,7 @@ mod test { let facet_candidates = None; - let mut criteria = Typo::initial(&context, Some(query_tree), facet_candidates).unwrap(); + let mut criteria = Typo::initial(&context, Some(query_tree), facet_candidates); let candidates_1 = context.word_docids("split").unwrap().unwrap() & context.word_docids("this").unwrap().unwrap() @@ -414,7 +410,7 @@ mod test { let query_tree = None; let facet_candidates = context.word_docids("earth").unwrap().unwrap(); - let mut criteria = Typo::initial(&context, query_tree, Some(facet_candidates.clone())).unwrap(); + let mut criteria = Typo::initial(&context, query_tree, Some(facet_candidates.clone())); let expected = CriterionResult { query_tree: None, @@ -442,7 +438,7 @@ mod test { let facet_candidates = context.word_docids("earth").unwrap().unwrap(); - let mut criteria = Typo::initial(&context, Some(query_tree), Some(facet_candidates.clone())).unwrap(); + let mut criteria = Typo::initial(&context, Some(query_tree), Some(facet_candidates.clone())); let candidates_1 = context.word_docids("split").unwrap().unwrap() & context.word_docids("this").unwrap().unwrap() diff --git a/milli/src/search/criteria/words.rs b/milli/src/search/criteria/words.rs index 08cbeaab3..1827cd1ed 100644 --- a/milli/src/search/criteria/words.rs +++ b/milli/src/search/criteria/words.rs @@ -21,31 +21,27 @@ impl<'t> Words<'t> { ctx: &'t dyn Context, query_tree: Option, candidates: Option, - ) -> anyhow::Result + ) -> Self { - Ok(Words { + Words { ctx, query_trees: query_tree.map(explode_query_tree).unwrap_or_default(), candidates: candidates.map_or_else(Candidates::default, Candidates::Allowed), bucket_candidates: RoaringBitmap::new(), parent: None, candidates_cache: HashMap::default(), - }) + } } - pub fn new( - ctx: &'t dyn Context, - parent: Box, - ) -> anyhow::Result - { - Ok(Words { + pub fn new(ctx: &'t dyn Context, parent: Box) -> Self { + Words { ctx, query_trees: Vec::default(), candidates: Candidates::default(), bucket_candidates: RoaringBitmap::new(), parent: Some(parent), candidates_cache: HashMap::default(), - }) + } } }