From d91d321129620b5ddf6c97acdbe5adb65a66a2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 27 Jan 2021 14:32:30 +0100 Subject: [PATCH] Introduce some constants to the FacetDistribution struct and settings --- src/search/facet/facet_distribution.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/search/facet/facet_distribution.rs b/src/search/facet/facet_distribution.rs index 06c84bf17..8bab2cb62 100644 --- a/src/search/facet/facet_distribution.rs +++ b/src/search/facet/facet_distribution.rs @@ -10,6 +10,18 @@ use crate::heed_codec::facet::{FieldDocIdFacetStringCodec, FieldDocIdFacetF64Cod use crate::search::facet::{FacetIter, FacetRange}; use crate::{Index, FieldId}; +/// The default number of values by facets that will +/// be fetched from the key-value store. +const DEFAULT_VALUES_BY_FACET: usize = 100; + +/// The hard limit in the number of values by facets that will be fetched from +/// the key-value store. Searching for more values could slow down the engine. +const MAX_VALUES_BY_FACET: usize = 1000; + +/// Threshold on the number of candidates that will make +/// the system to choose between one algorithm or another. +const CANDIDATES_THRESHOLD: u64 = 1000; + pub struct FacetDistribution<'a> { facets: Option>, candidates: Option, @@ -20,7 +32,13 @@ pub struct FacetDistribution<'a> { impl<'a> FacetDistribution<'a> { pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index) -> FacetDistribution<'a> { - FacetDistribution { facets: None, candidates: None, max_values_by_facet: 100, rtxn, index } + FacetDistribution { + facets: None, + candidates: None, + max_values_by_facet: DEFAULT_VALUES_BY_FACET, + rtxn, + index, + } } pub fn facets, A: AsRef>(&mut self, names: I) -> &mut Self { @@ -34,7 +52,7 @@ impl<'a> FacetDistribution<'a> { } pub fn max_values_by_facet(&mut self, max: usize) -> &mut Self { - self.max_values_by_facet = cmp::min(max, 1000); + self.max_values_by_facet = cmp::min(max, MAX_VALUES_BY_FACET); self } @@ -45,7 +63,7 @@ impl<'a> FacetDistribution<'a> { ) -> heed::Result> { if let Some(candidates) = self.candidates.as_ref() { - if candidates.len() <= 1000 { + if candidates.len() <= CANDIDATES_THRESHOLD { let mut key_buffer = vec![field_id]; match facet_type { FacetType::Float => {