Change the criterion output that cannot fail

This commit is contained in:
Kerollmops 2021-03-03 18:16:13 +01:00
parent 1fc25148da
commit 2cc4a467a6
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
4 changed files with 28 additions and 40 deletions

View File

@ -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)?)

View File

@ -22,9 +22,9 @@ impl<'t> Proximity<'t> {
ctx: &'t dyn Context,
query_tree: Option<Operation>,
candidates: Option<RoaringBitmap>,
) -> anyhow::Result<Self>
) -> 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<dyn Criterion + 't>,
) -> anyhow::Result<Self>
{
Ok(Proximity {
pub fn new(ctx: &'t dyn Context, parent: Box<dyn Criterion + 't>) -> 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(),
})
}
}
}

View File

@ -24,9 +24,9 @@ impl<'t> Typo<'t> {
ctx: &'t dyn Context,
query_tree: Option<Operation>,
candidates: Option<RoaringBitmap>,
) -> anyhow::Result<Self>
) -> 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<dyn Criterion + 't>,
) -> anyhow::Result<Self>
{
Ok(Typo {
pub fn new(ctx: &'t dyn Context, parent: Box<dyn Criterion + 't>) -> 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()

View File

@ -21,31 +21,27 @@ impl<'t> Words<'t> {
ctx: &'t dyn Context,
query_tree: Option<Operation>,
candidates: Option<RoaringBitmap>,
) -> anyhow::Result<Self>
) -> 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<dyn Criterion + 't>,
) -> anyhow::Result<Self>
{
Ok(Words {
pub fn new(ctx: &'t dyn Context, parent: Box<dyn Criterion + 't>) -> Self {
Words {
ctx,
query_trees: Vec::default(),
candidates: Candidates::default(),
bucket_candidates: RoaringBitmap::new(),
parent: Some(parent),
candidates_cache: HashMap::default(),
})
}
}
}