mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 09:04:59 +08:00
Use the facet string levels when computing the facet distribution
This commit is contained in:
parent
5676b204dd
commit
081278dfd6
@ -9,7 +9,7 @@ use roaring::RoaringBitmap;
|
|||||||
use crate::error::{FieldIdMapMissingEntry, UserError};
|
use crate::error::{FieldIdMapMissingEntry, UserError};
|
||||||
use crate::facet::FacetType;
|
use crate::facet::FacetType;
|
||||||
use crate::heed_codec::facet::FacetStringLevelZeroCodec;
|
use crate::heed_codec::facet::FacetStringLevelZeroCodec;
|
||||||
use crate::search::facet::{FacetNumberIter, FacetNumberRange};
|
use crate::search::facet::{FacetNumberIter, FacetNumberRange, FacetStringIter};
|
||||||
use crate::{DocumentId, FieldId, Index, Result};
|
use crate::{DocumentId, FieldId, Index, Result};
|
||||||
|
|
||||||
/// The default number of values by facets that will
|
/// The default number of values by facets that will
|
||||||
@ -134,6 +134,29 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn facet_strings_distribution_from_facet_levels(
|
||||||
|
&self,
|
||||||
|
field_id: FieldId,
|
||||||
|
candidates: &RoaringBitmap,
|
||||||
|
distribution: &mut BTreeMap<String, u64>,
|
||||||
|
) -> heed::Result<()> {
|
||||||
|
let iter =
|
||||||
|
FacetStringIter::new_non_reducing(self.rtxn, self.index, field_id, candidates.clone())?;
|
||||||
|
|
||||||
|
for result in iter {
|
||||||
|
let (value, mut docids) = result?;
|
||||||
|
docids &= candidates;
|
||||||
|
if !docids.is_empty() {
|
||||||
|
distribution.insert(value.to_string(), docids.len());
|
||||||
|
}
|
||||||
|
if distribution.len() == self.max_values_by_facet {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Placeholder search, a.k.a. no candidates were specified. We iterate throught the
|
/// Placeholder search, a.k.a. no candidates were specified. We iterate throught the
|
||||||
/// facet values one by one and iterate on the facet level 0 for numbers.
|
/// facet values one by one and iterate on the facet level 0 for numbers.
|
||||||
fn facet_values_from_raw_facet_database(
|
fn facet_values_from_raw_facet_database(
|
||||||
@ -198,9 +221,8 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
candidates,
|
candidates,
|
||||||
&mut distribution,
|
&mut distribution,
|
||||||
)?;
|
)?;
|
||||||
self.facet_distribution_from_documents(
|
self.facet_strings_distribution_from_facet_levels(
|
||||||
field_id,
|
field_id,
|
||||||
String,
|
|
||||||
candidates,
|
candidates,
|
||||||
&mut distribution,
|
&mut distribution,
|
||||||
)?;
|
)?;
|
||||||
|
@ -192,7 +192,7 @@ impl<'t> Iterator for FacetStringGroupRange<'t> {
|
|||||||
};
|
};
|
||||||
if must_be_returned {
|
if must_be_returned {
|
||||||
match docids.decode() {
|
match docids.decode() {
|
||||||
Ok(docids) => Some(Ok(((level, left, right), docids))),
|
Ok((bounds, docids)) => Some(Ok(((level, left, right), (bounds, docids)))),
|
||||||
Err(e) => Some(Err(e)),
|
Err(e) => Some(Err(e)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
pub use self::facet_distribution::FacetDistribution;
|
pub use self::facet_distribution::FacetDistribution;
|
||||||
pub use self::facet_number::{FacetNumberIter, FacetNumberRange, FacetNumberRevRange};
|
pub use self::facet_number::{FacetNumberIter, FacetNumberRange, FacetNumberRevRange};
|
||||||
|
pub use self::facet_string::FacetStringIter;
|
||||||
pub use self::filter_condition::{FilterCondition, Operator};
|
pub use self::filter_condition::{FilterCondition, Operator};
|
||||||
pub(crate) use self::parser::Rule as ParserRule;
|
pub(crate) use self::parser::Rule as ParserRule;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user