mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
Fix a bound error in the facet string range construction
This commit is contained in:
parent
081278dfd6
commit
d23c250ad5
@ -22,7 +22,7 @@ const MAX_VALUES_BY_FACET: usize = 1000;
|
|||||||
|
|
||||||
/// Threshold on the number of candidates that will make
|
/// Threshold on the number of candidates that will make
|
||||||
/// the system to choose between one algorithm or another.
|
/// the system to choose between one algorithm or another.
|
||||||
const CANDIDATES_THRESHOLD: u64 = 1000;
|
const CANDIDATES_THRESHOLD: u64 = 35_000;
|
||||||
|
|
||||||
pub struct FacetDistribution<'a> {
|
pub struct FacetDistribution<'a> {
|
||||||
facets: Option<HashSet<String>>,
|
facets: Option<HashSet<String>>,
|
||||||
@ -80,7 +80,7 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
{
|
{
|
||||||
let mut key_buffer: Vec<_> = field_id.to_be_bytes().iter().copied().collect();
|
let mut key_buffer: Vec<_> = field_id.to_be_bytes().iter().copied().collect();
|
||||||
|
|
||||||
for docid in candidates.into_iter().take(CANDIDATES_THRESHOLD as usize) {
|
for docid in candidates.into_iter() {
|
||||||
key_buffer.truncate(mem::size_of::<FieldId>());
|
key_buffer.truncate(mem::size_of::<FieldId>());
|
||||||
key_buffer.extend_from_slice(&docid.to_be_bytes());
|
key_buffer.extend_from_slice(&docid.to_be_bytes());
|
||||||
let iter = db
|
let iter = db
|
||||||
|
@ -220,36 +220,34 @@ impl<'t> FacetStringLevelZeroRange<'t> {
|
|||||||
left: Bound<&str>,
|
left: Bound<&str>,
|
||||||
right: Bound<&str>,
|
right: Bound<&str>,
|
||||||
) -> heed::Result<FacetStringLevelZeroRange<'t>> {
|
) -> heed::Result<FacetStringLevelZeroRange<'t>> {
|
||||||
fn encode_bound<'a>(
|
fn encode_value<'a>(buffer: &'a mut Vec<u8>, field_id: FieldId, value: &str) -> &'a [u8] {
|
||||||
buffer: &'a mut Vec<u8>,
|
|
||||||
field_id: FieldId,
|
|
||||||
bound: Bound<&str>,
|
|
||||||
) -> Bound<&'a [u8]> {
|
|
||||||
match bound {
|
|
||||||
Included(value) => {
|
|
||||||
buffer.extend_from_slice(&field_id.to_be_bytes());
|
buffer.extend_from_slice(&field_id.to_be_bytes());
|
||||||
buffer.push(0);
|
buffer.push(0);
|
||||||
buffer.extend_from_slice(value.as_bytes());
|
buffer.extend_from_slice(value.as_bytes());
|
||||||
Included(&buffer[..])
|
&buffer[..]
|
||||||
}
|
|
||||||
Excluded(value) => {
|
|
||||||
buffer.extend_from_slice(&field_id.to_be_bytes());
|
|
||||||
buffer.push(0);
|
|
||||||
buffer.extend_from_slice(value.as_bytes());
|
|
||||||
Excluded(&buffer[..])
|
|
||||||
}
|
|
||||||
Unbounded => {
|
|
||||||
buffer.extend_from_slice(&field_id.to_be_bytes());
|
|
||||||
buffer.push(1); // we must only get the level 0
|
|
||||||
Excluded(&buffer[..])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut left_buffer = Vec::new();
|
let mut left_buffer = Vec::new();
|
||||||
|
let left_bound = match left {
|
||||||
|
Included(value) => Included(encode_value(&mut left_buffer, field_id, value)),
|
||||||
|
Excluded(value) => Excluded(encode_value(&mut left_buffer, field_id, value)),
|
||||||
|
Unbounded => {
|
||||||
|
left_buffer.extend_from_slice(&field_id.to_be_bytes());
|
||||||
|
left_buffer.push(0);
|
||||||
|
Included(&left_buffer[..])
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let mut right_buffer = Vec::new();
|
let mut right_buffer = Vec::new();
|
||||||
let left_bound = encode_bound(&mut left_buffer, field_id, left);
|
let right_bound = match right {
|
||||||
let right_bound = encode_bound(&mut right_buffer, field_id, right);
|
Included(value) => Included(encode_value(&mut right_buffer, field_id, value)),
|
||||||
|
Excluded(value) => Excluded(encode_value(&mut right_buffer, field_id, value)),
|
||||||
|
Unbounded => {
|
||||||
|
right_buffer.extend_from_slice(&field_id.to_be_bytes());
|
||||||
|
right_buffer.push(1); // we must only get the level 0
|
||||||
|
Excluded(&right_buffer[..])
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let iter = db
|
let iter = db
|
||||||
.remap_key_type::<ByteSlice>()
|
.remap_key_type::<ByteSlice>()
|
||||||
@ -290,7 +288,6 @@ impl<'t> FacetStringIter<'t> {
|
|||||||
field_id: FieldId,
|
field_id: FieldId,
|
||||||
documents_ids: RoaringBitmap,
|
documents_ids: RoaringBitmap,
|
||||||
) -> heed::Result<FacetStringIter<'t>> {
|
) -> heed::Result<FacetStringIter<'t>> {
|
||||||
// TODO make sure that we change the database before using it, or merging the PR.
|
|
||||||
let db = index.facet_id_string_docids.remap_types::<ByteSlice, ByteSlice>();
|
let db = index.facet_id_string_docids.remap_types::<ByteSlice, ByteSlice>();
|
||||||
let highest_level = Self::highest_level(rtxn, db, field_id)?.unwrap_or(0);
|
let highest_level = Self::highest_level(rtxn, db, field_id)?.unwrap_or(0);
|
||||||
let highest_iter = match NonZeroU8::new(highest_level) {
|
let highest_iter = match NonZeroU8::new(highest_level) {
|
||||||
|
Loading…
Reference in New Issue
Block a user