From 44b6843de78925860239c9977048fe31fc11fcc8 Mon Sep 17 00:00:00 2001 From: Many Date: Thu, 6 May 2021 11:24:46 +0200 Subject: [PATCH] Fix pull request reviews Update milli/src/fields_ids_map.rs Update milli/src/search/criteria/exactness.rs Update milli/src/search/criteria/mod.rs --- milli/src/fields_ids_map.rs | 4 ++-- milli/src/search/criteria/exactness.rs | 29 +++++++------------------- milli/src/search/criteria/mod.rs | 11 +++++----- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/milli/src/fields_ids_map.rs b/milli/src/fields_ids_map.rs index 6eed9c41f..76ff2d281 100644 --- a/milli/src/fields_ids_map.rs +++ b/milli/src/fields_ids_map.rs @@ -66,12 +66,12 @@ impl FieldsIdsMap { self.ids_names.iter().map(|(id, name)| (*id, name.as_str())) } - /// Iterate over the ids in the ids order. + /// Iterate over the ids in the order of the ids. pub fn ids<'a>(&'a self) -> impl Iterator + 'a { self.ids_names.keys().copied() } - /// Iterate over the names in the ids order. + /// Iterate over the names in the order of the ids. pub fn names(&self) -> impl Iterator { self.ids_names.values().map(AsRef::as_ref) } diff --git a/milli/src/search/criteria/exactness.rs b/milli/src/search/criteria/exactness.rs index e7ece6e91..c004f4a51 100644 --- a/milli/src/search/criteria/exactness.rs +++ b/milli/src/search/criteria/exactness.rs @@ -51,7 +51,7 @@ impl<'t> Criterion for Exactness<'t> { } loop { - debug!("Exactness for query {:?} at state {:?}", self.query, self.state); + debug!("Exactness at state {:?}", self.state); match self.state.as_mut() { Some(state) if state.is_empty() => { @@ -296,27 +296,12 @@ fn attribute_start_with_docids(ctx: &dyn Context, attribute_id: u32, query: &[Ex Ok(attribute_candidates_array) } -fn intersection_of(mut to_intersect: Vec<&RoaringBitmap>) -> RoaringBitmap { - match to_intersect.len() { - 0 => RoaringBitmap::new(), - 1 => to_intersect[0].clone(), - 2 => to_intersect[0] & to_intersect[1], - _ => { - to_intersect.sort_unstable_by(|a, b| a.len().cmp(&b.len()).reverse()); - - match to_intersect.pop() { - None => RoaringBitmap::new(), - Some(candidates) => { - let mut candidates = candidates.clone(); - while let Some(bitmap) = to_intersect.pop() { - if candidates.is_empty() { break; } - candidates &= bitmap; - } - - candidates - }, - } - } +fn intersection_of(mut rbs: Vec<&RoaringBitmap>) -> RoaringBitmap { + rbs.sort_unstable_by_key(|rb| rb.len()); + let mut iter = rbs.into_iter(); + match iter.next() { + Some(first) => iter.fold(first.clone(), |acc, rb| acc & rb), + None => RoaringBitmap::new(), } } diff --git a/milli/src/search/criteria/mod.rs b/milli/src/search/criteria/mod.rs index d2fd808f9..76e263036 100644 --- a/milli/src/search/criteria/mod.rs +++ b/milli/src/search/criteria/mod.rs @@ -7,7 +7,7 @@ use roaring::RoaringBitmap; use crate::{FieldId, TreeLevel, search::{word_derivations, WordDerivationsCache}}; use crate::{Index, DocumentId}; -use super::query_tree::{Operation, PrimitiveQuery, PrimitiveQueryPart, Query, QueryKind}; +use super::query_tree::{Operation, PrimitiveQueryPart, Query, QueryKind}; use self::asc_desc::AscDesc; use self::attribute::Attribute; use self::exactness::Exactness; @@ -188,7 +188,7 @@ impl<'c> Context<'c> for CriteriaBuilder<'c> { } } - fn field_id_len_docids(&self, field_id: FieldId, len: u32) -> heed::Result> { + fn field_id_len_docids(&self, _field_id: FieldId, _len: u32) -> heed::Result> { Ok(None) } @@ -226,7 +226,6 @@ impl<'t> CriteriaBuilder<'t> { Name::Exactness => Box::new(Exactness::new(self, criterion, &primitive_query)?), Name::Asc(field) => Box::new(AscDesc::asc(&self.index, &self.rtxn, criterion, field)?), Name::Desc(field) => Box::new(AscDesc::desc(&self.index, &self.rtxn, criterion, field)?), - _otherwise => criterion, }; } @@ -486,7 +485,7 @@ pub mod test { todo!() } - fn synonyms(&self, word: &str) -> heed::Result>>> { + fn synonyms(&self, _word: &str) -> heed::Result>>> { todo!() } @@ -494,11 +493,11 @@ pub mod test { todo!() } - fn word_level_position_docids(&self, word: &str, level: TreeLevel, left: u32, right: u32) -> Result, heed::Error> { + fn word_level_position_docids(&self, _word: &str, _level: TreeLevel, _left: u32, _right: u32) -> Result, heed::Error> { todo!() } - fn field_id_len_docids(&self, field_id: FieldId, len: u32) -> heed::Result> { + fn field_id_len_docids(&self, _field_id: FieldId, _len: u32) -> heed::Result> { todo!() } }