mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
Change the criterion output that cannot fail
This commit is contained in:
parent
1fc25148da
commit
2cc4a467a6
@ -138,9 +138,9 @@ impl<'t> CriteriaBuilder<'t> {
|
|||||||
for name in self.index.criteria(&self.rtxn)? {
|
for name in self.index.criteria(&self.rtxn)? {
|
||||||
criterion = Some(match criterion.take() {
|
criterion = Some(match criterion.take() {
|
||||||
Some(father) => match name {
|
Some(father) => match name {
|
||||||
Name::Typo => Box::new(Typo::new(self, father)?),
|
Name::Typo => Box::new(Typo::new(self, father)),
|
||||||
Name::Words => Box::new(Words::new(self, father)?),
|
Name::Words => Box::new(Words::new(self, father)),
|
||||||
Name::Proximity => Box::new(Proximity::new(self, father)?),
|
Name::Proximity => Box::new(Proximity::new(self, father)),
|
||||||
Name::Asc(field) => {
|
Name::Asc(field) => {
|
||||||
let (id, facet_type) = field_id_facet_type(&field)?;
|
let (id, facet_type) = field_id_facet_type(&field)?;
|
||||||
Box::new(AscDesc::asc(&self.index, &self.rtxn, father, id, facet_type)?)
|
Box::new(AscDesc::asc(&self.index, &self.rtxn, father, id, facet_type)?)
|
||||||
@ -152,9 +152,9 @@ impl<'t> CriteriaBuilder<'t> {
|
|||||||
_otherwise => father,
|
_otherwise => father,
|
||||||
},
|
},
|
||||||
None => match name {
|
None => match name {
|
||||||
Name::Typo => Box::new(Typo::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::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::Proximity => Box::new(Proximity::initial(self, query_tree.take(), facet_candidates.take())),
|
||||||
Name::Asc(field) => {
|
Name::Asc(field) => {
|
||||||
let (id, facet_type) = field_id_facet_type(&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)?)
|
Box::new(AscDesc::initial_asc(&self.index, &self.rtxn, query_tree.take(), facet_candidates.take(), id, facet_type)?)
|
||||||
|
@ -22,9 +22,9 @@ impl<'t> Proximity<'t> {
|
|||||||
ctx: &'t dyn Context,
|
ctx: &'t dyn Context,
|
||||||
query_tree: Option<Operation>,
|
query_tree: Option<Operation>,
|
||||||
candidates: Option<RoaringBitmap>,
|
candidates: Option<RoaringBitmap>,
|
||||||
) -> anyhow::Result<Self>
|
) -> Self
|
||||||
{
|
{
|
||||||
Ok(Proximity {
|
Proximity {
|
||||||
ctx,
|
ctx,
|
||||||
query_tree: query_tree.map(|op| (maximum_proximity(&op), op)),
|
query_tree: query_tree.map(|op| (maximum_proximity(&op), op)),
|
||||||
proximity: 0,
|
proximity: 0,
|
||||||
@ -32,15 +32,11 @@ impl<'t> Proximity<'t> {
|
|||||||
bucket_candidates: RoaringBitmap::new(),
|
bucket_candidates: RoaringBitmap::new(),
|
||||||
parent: None,
|
parent: None,
|
||||||
candidates_cache: HashMap::new(),
|
candidates_cache: HashMap::new(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(ctx: &'t dyn Context, parent: Box<dyn Criterion + 't>) -> Self {
|
||||||
ctx: &'t dyn Context,
|
Proximity {
|
||||||
parent: Box<dyn Criterion + 't>,
|
|
||||||
) -> anyhow::Result<Self>
|
|
||||||
{
|
|
||||||
Ok(Proximity {
|
|
||||||
ctx,
|
ctx,
|
||||||
query_tree: None,
|
query_tree: None,
|
||||||
proximity: 0,
|
proximity: 0,
|
||||||
@ -48,7 +44,7 @@ impl<'t> Proximity<'t> {
|
|||||||
bucket_candidates: RoaringBitmap::new(),
|
bucket_candidates: RoaringBitmap::new(),
|
||||||
parent: Some(parent),
|
parent: Some(parent),
|
||||||
candidates_cache: HashMap::new(),
|
candidates_cache: HashMap::new(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ impl<'t> Typo<'t> {
|
|||||||
ctx: &'t dyn Context,
|
ctx: &'t dyn Context,
|
||||||
query_tree: Option<Operation>,
|
query_tree: Option<Operation>,
|
||||||
candidates: Option<RoaringBitmap>,
|
candidates: Option<RoaringBitmap>,
|
||||||
) -> anyhow::Result<Self>
|
) -> Self
|
||||||
{
|
{
|
||||||
Ok(Typo {
|
Typo {
|
||||||
ctx,
|
ctx,
|
||||||
query_tree: query_tree.map(|op| (maximum_typo(&op), op)),
|
query_tree: query_tree.map(|op| (maximum_typo(&op), op)),
|
||||||
number_typos: 0,
|
number_typos: 0,
|
||||||
@ -35,15 +35,11 @@ impl<'t> Typo<'t> {
|
|||||||
parent: None,
|
parent: None,
|
||||||
candidates_cache: HashMap::new(),
|
candidates_cache: HashMap::new(),
|
||||||
typo_cache: HashMap::new(),
|
typo_cache: HashMap::new(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(ctx: &'t dyn Context, parent: Box<dyn Criterion + 't>) -> Self {
|
||||||
ctx: &'t dyn Context,
|
Typo {
|
||||||
parent: Box<dyn Criterion + 't>,
|
|
||||||
) -> anyhow::Result<Self>
|
|
||||||
{
|
|
||||||
Ok(Typo {
|
|
||||||
ctx,
|
ctx,
|
||||||
query_tree: None,
|
query_tree: None,
|
||||||
number_typos: 0,
|
number_typos: 0,
|
||||||
@ -52,7 +48,7 @@ impl<'t> Typo<'t> {
|
|||||||
parent: Some(parent),
|
parent: Some(parent),
|
||||||
candidates_cache: HashMap::new(),
|
candidates_cache: HashMap::new(),
|
||||||
typo_cache: HashMap::new(),
|
typo_cache: HashMap::new(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +344,7 @@ mod test {
|
|||||||
let query_tree = None;
|
let query_tree = None;
|
||||||
let facet_candidates = 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());
|
assert!(criteria.next().unwrap().is_none());
|
||||||
}
|
}
|
||||||
@ -366,7 +362,7 @@ mod test {
|
|||||||
|
|
||||||
let facet_candidates = None;
|
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()
|
let candidates_1 = context.word_docids("split").unwrap().unwrap()
|
||||||
& context.word_docids("this").unwrap().unwrap()
|
& context.word_docids("this").unwrap().unwrap()
|
||||||
@ -414,7 +410,7 @@ mod test {
|
|||||||
let query_tree = None;
|
let query_tree = None;
|
||||||
let facet_candidates = context.word_docids("earth").unwrap().unwrap();
|
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 {
|
let expected = CriterionResult {
|
||||||
query_tree: None,
|
query_tree: None,
|
||||||
@ -442,7 +438,7 @@ mod test {
|
|||||||
|
|
||||||
let facet_candidates = context.word_docids("earth").unwrap().unwrap();
|
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()
|
let candidates_1 = context.word_docids("split").unwrap().unwrap()
|
||||||
& context.word_docids("this").unwrap().unwrap()
|
& context.word_docids("this").unwrap().unwrap()
|
||||||
|
@ -21,31 +21,27 @@ impl<'t> Words<'t> {
|
|||||||
ctx: &'t dyn Context,
|
ctx: &'t dyn Context,
|
||||||
query_tree: Option<Operation>,
|
query_tree: Option<Operation>,
|
||||||
candidates: Option<RoaringBitmap>,
|
candidates: Option<RoaringBitmap>,
|
||||||
) -> anyhow::Result<Self>
|
) -> Self
|
||||||
{
|
{
|
||||||
Ok(Words {
|
Words {
|
||||||
ctx,
|
ctx,
|
||||||
query_trees: query_tree.map(explode_query_tree).unwrap_or_default(),
|
query_trees: query_tree.map(explode_query_tree).unwrap_or_default(),
|
||||||
candidates: candidates.map_or_else(Candidates::default, Candidates::Allowed),
|
candidates: candidates.map_or_else(Candidates::default, Candidates::Allowed),
|
||||||
bucket_candidates: RoaringBitmap::new(),
|
bucket_candidates: RoaringBitmap::new(),
|
||||||
parent: None,
|
parent: None,
|
||||||
candidates_cache: HashMap::default(),
|
candidates_cache: HashMap::default(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(ctx: &'t dyn Context, parent: Box<dyn Criterion + 't>) -> Self {
|
||||||
ctx: &'t dyn Context,
|
Words {
|
||||||
parent: Box<dyn Criterion + 't>,
|
|
||||||
) -> anyhow::Result<Self>
|
|
||||||
{
|
|
||||||
Ok(Words {
|
|
||||||
ctx,
|
ctx,
|
||||||
query_trees: Vec::default(),
|
query_trees: Vec::default(),
|
||||||
candidates: Candidates::default(),
|
candidates: Candidates::default(),
|
||||||
bucket_candidates: RoaringBitmap::new(),
|
bucket_candidates: RoaringBitmap::new(),
|
||||||
parent: Some(parent),
|
parent: Some(parent),
|
||||||
candidates_cache: HashMap::default(),
|
candidates_cache: HashMap::default(),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user