Introduce mocked ExactAttribute step in exactness criterion

This commit is contained in:
many 2021-05-04 15:28:05 +02:00
parent a3f8686fbf
commit c1ce4e4ca9
No known key found for this signature in database
GPG Key ID: 2CEF23B75189EACA
2 changed files with 31 additions and 5 deletions

View File

@ -150,7 +150,25 @@ fn resolve_state(
{ {
use State::*; use State::*;
match state { match state {
ExactAttribute(mut allowed_candidates) | ExactAttribute(mut allowed_candidates) => {
let query_len = query.len() as u32;
let mut candidates = RoaringBitmap::new();
let attributes_ids = ctx.searchable_fields_ids()?;
for id in attributes_ids {
if let Some(attribute_allowed_docids) = ctx.field_id_len_docids(id, query_len)? {
let mut attribute_candidates_array = attribute_start_with_docids(ctx, id as u32, query)?;
attribute_candidates_array.push(attribute_allowed_docids);
candidates |= intersection_of(attribute_candidates_array.iter().collect());
}
}
// only keep allowed candidates
candidates &= &allowed_candidates;
// remove current candidates from allowed candidates
allowed_candidates -= &candidates;
Ok((candidates, Some(AttributeStartsWith(allowed_candidates))))
},
AttributeStartsWith(mut allowed_candidates) => { AttributeStartsWith(mut allowed_candidates) => {
let mut candidates = RoaringBitmap::new(); let mut candidates = RoaringBitmap::new();
let attributes_ids = ctx.searchable_fields_ids()?; let attributes_ids = ctx.searchable_fields_ids()?;

View File

@ -4,7 +4,7 @@ use std::borrow::Cow;
use anyhow::bail; use anyhow::bail;
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
use crate::{TreeLevel, search::{word_derivations, WordDerivationsCache}}; use crate::{FieldId, TreeLevel, search::{word_derivations, WordDerivationsCache}};
use crate::{Index, DocumentId}; use crate::{Index, DocumentId};
use super::query_tree::{Operation, PrimitiveQuery, PrimitiveQueryPart, Query, QueryKind}; use super::query_tree::{Operation, PrimitiveQuery, PrimitiveQueryPart, Query, QueryKind};
@ -84,7 +84,8 @@ pub trait Context<'c> {
fn word_position_iterator(&self, word: &str, level: TreeLevel, in_prefix_cache: bool, left: Option<u32>, right: Option<u32>) -> heed::Result<Box<dyn Iterator<Item =heed::Result<((&'c str, TreeLevel, u32, u32), RoaringBitmap)>> + 'c>>; fn word_position_iterator(&self, word: &str, level: TreeLevel, in_prefix_cache: bool, left: Option<u32>, right: Option<u32>) -> heed::Result<Box<dyn Iterator<Item =heed::Result<((&'c str, TreeLevel, u32, u32), RoaringBitmap)>> + 'c>>;
fn word_position_last_level(&self, word: &str, in_prefix_cache: bool) -> heed::Result<Option<TreeLevel>>; fn word_position_last_level(&self, word: &str, in_prefix_cache: bool) -> heed::Result<Option<TreeLevel>>;
fn synonyms(&self, word: &str) -> heed::Result<Option<Vec<Vec<String>>>>; fn synonyms(&self, word: &str) -> heed::Result<Option<Vec<Vec<String>>>>;
fn searchable_fields_ids(&self) -> heed::Result<Vec<crate::FieldId>>; fn searchable_fields_ids(&self) -> heed::Result<Vec<FieldId>>;
fn field_id_len_docids(&self, field_id: FieldId, len: u32) -> heed::Result<Option<RoaringBitmap>>;
fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result<Option<RoaringBitmap>, heed::Error>; fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result<Option<RoaringBitmap>, heed::Error>;
} }
pub struct CriteriaBuilder<'t> { pub struct CriteriaBuilder<'t> {
@ -180,12 +181,15 @@ impl<'c> Context<'c> for CriteriaBuilder<'c> {
self.index.words_synonyms(self.rtxn, &[word]) self.index.words_synonyms(self.rtxn, &[word])
} }
fn searchable_fields_ids(&self) -> heed::Result<Vec<crate::FieldId>> { fn searchable_fields_ids(&self) -> heed::Result<Vec<FieldId>> {
match self.index.searchable_fields_ids(self.rtxn)? { match self.index.searchable_fields_ids(self.rtxn)? {
Some(searchable_fields_ids) => Ok(searchable_fields_ids), Some(searchable_fields_ids) => Ok(searchable_fields_ids),
None => Ok(self.index.fields_ids_map(self.rtxn)?.ids().collect()), None => Ok(self.index.fields_ids_map(self.rtxn)?.ids().collect()),
} }
}
fn field_id_len_docids(&self, field_id: FieldId, len: u32) -> heed::Result<Option<RoaringBitmap>> {
Ok(None)
} }
fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result<Option<RoaringBitmap>, heed::Error> { fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result<Option<RoaringBitmap>, heed::Error> {
@ -486,13 +490,17 @@ pub mod test {
todo!() todo!()
} }
fn searchable_fields_ids(&self) -> heed::Result<Vec<crate::FieldId>> { fn searchable_fields_ids(&self) -> heed::Result<Vec<FieldId>> {
todo!() todo!()
} }
fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result<Option<RoaringBitmap>, heed::Error> { fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result<Option<RoaringBitmap>, heed::Error> {
todo!() todo!()
} }
fn field_id_len_docids(&self, field_id: FieldId, len: u32) -> heed::Result<Option<RoaringBitmap>> {
todo!()
}
} }
impl<'a> Default for TestContext<'a> { impl<'a> Default for TestContext<'a> {