From c701f8bf36fbba25413f00ab1e8ebf7abeefb0a4 Mon Sep 17 00:00:00 2001 From: many Date: Thu, 27 May 2021 15:32:14 +0200 Subject: [PATCH] Use field id word count database in exactness criterion --- milli/src/search/criteria/exactness.rs | 4 ++-- milli/src/search/criteria/mod.rs | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/milli/src/search/criteria/exactness.rs b/milli/src/search/criteria/exactness.rs index b1026ccc2..7f27287b7 100644 --- a/milli/src/search/criteria/exactness.rs +++ b/milli/src/search/criteria/exactness.rs @@ -162,11 +162,11 @@ fn resolve_state( use State::*; match state { ExactAttribute(mut allowed_candidates) => { - let query_len = query.len() as u32; + let query_len = query.len() as u8; 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)? { + if let Some(attribute_allowed_docids) = ctx.field_id_word_count_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()); diff --git a/milli/src/search/criteria/mod.rs b/milli/src/search/criteria/mod.rs index 99e4a4209..456d16e1a 100644 --- a/milli/src/search/criteria/mod.rs +++ b/milli/src/search/criteria/mod.rs @@ -78,7 +78,7 @@ pub trait Context<'c> { fn word_position_last_level(&self, word: &str, in_prefix_cache: bool) -> heed::Result>; fn synonyms(&self, word: &str) -> heed::Result>>>; fn searchable_fields_ids(&self) -> heed::Result>; - fn field_id_len_docids(&self, field_id: FieldId, len: u32) -> heed::Result>; + fn field_id_word_count_docids(&self, field_id: FieldId, word_count: u8) -> heed::Result>; fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result, heed::Error>; } pub struct CriteriaBuilder<'t> { @@ -181,8 +181,9 @@ impl<'c> Context<'c> for CriteriaBuilder<'c> { } } - fn field_id_len_docids(&self, _field_id: FieldId, _len: u32) -> heed::Result> { - Ok(None) + fn field_id_word_count_docids(&self, field_id: FieldId, word_count: u8) -> heed::Result> { + let key = (field_id, word_count); + self.index.field_id_word_count_docids.get(self.rtxn, &key) } fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result, heed::Error> { @@ -488,7 +489,7 @@ pub mod test { todo!() } - fn field_id_len_docids(&self, _field_id: FieldId, _len: u32) -> heed::Result> { + fn field_id_word_count_docids(&self, _field_id: FieldId, _word_count: u8) -> heed::Result> { todo!() } }