mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 01:57:41 +08:00
Fix crashes in facet search indexing
This commit is contained in:
parent
7864530589
commit
1f5d801271
@ -28,7 +28,6 @@ impl From<u8> for FacetKind {
|
||||
|
||||
impl FacetKind {
|
||||
pub fn extract_from_key(key: &[u8]) -> (FacetKind, &[u8]) {
|
||||
debug_assert!(key.len() > 3);
|
||||
(FacetKind::from(key[0]), &key[1..])
|
||||
}
|
||||
}
|
||||
|
@ -54,23 +54,12 @@ impl<'indexer> FacetSearchBuilder<'indexer> {
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_key_data<'k>(&self, key: &'k [u8]) -> Result<Option<FacetGroupKey<&'k str>>> {
|
||||
match FacetKind::from(key[0]) {
|
||||
// Only strings are searchable
|
||||
FacetKind::String => Ok(Some(
|
||||
FacetGroupKeyCodec::<StrRefCodec>::bytes_decode(&key[1..])
|
||||
.map_err(heed::Error::Encoding)?,
|
||||
)),
|
||||
_ => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_from_key(&mut self, deladd: DelAdd, facet_key: &[u8]) -> Result<()> {
|
||||
let Some(FacetGroupKey { field_id, level: _level, left_bound }) =
|
||||
self.extract_key_data(facet_key)?
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
pub fn register_from_key(
|
||||
&mut self,
|
||||
deladd: DelAdd,
|
||||
facet_key: FacetGroupKey<&str>,
|
||||
) -> Result<()> {
|
||||
let FacetGroupKey { field_id, level: _level, left_bound } = facet_key;
|
||||
|
||||
if deladd == DelAdd::Addition {
|
||||
self.registered_facets.entry(field_id).and_modify(|count| *count += 1).or_insert(1);
|
||||
|
@ -681,13 +681,11 @@ fn compute_facet_search_database(
|
||||
}
|
||||
EitherOrBoth::Left(result) => {
|
||||
let (key, _) = result?;
|
||||
facet_search_builder
|
||||
.register_from_key(DelAdd::Deletion, key.left_bound.as_ref())?;
|
||||
facet_search_builder.register_from_key(DelAdd::Deletion, key)?;
|
||||
}
|
||||
EitherOrBoth::Right(result) => {
|
||||
let (key, _) = result?;
|
||||
facet_search_builder
|
||||
.register_from_key(DelAdd::Addition, key.left_bound.as_ref())?;
|
||||
facet_search_builder.register_from_key(DelAdd::Addition, key)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user