mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-25 19:45:05 +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 {
|
impl FacetKind {
|
||||||
pub fn extract_from_key(key: &[u8]) -> (FacetKind, &[u8]) {
|
pub fn extract_from_key(key: &[u8]) -> (FacetKind, &[u8]) {
|
||||||
debug_assert!(key.len() > 3);
|
|
||||||
(FacetKind::from(key[0]), &key[1..])
|
(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>>> {
|
pub fn register_from_key(
|
||||||
match FacetKind::from(key[0]) {
|
&mut self,
|
||||||
// Only strings are searchable
|
deladd: DelAdd,
|
||||||
FacetKind::String => Ok(Some(
|
facet_key: FacetGroupKey<&str>,
|
||||||
FacetGroupKeyCodec::<StrRefCodec>::bytes_decode(&key[1..])
|
) -> Result<()> {
|
||||||
.map_err(heed::Error::Encoding)?,
|
let FacetGroupKey { field_id, level: _level, left_bound } = facet_key;
|
||||||
)),
|
|
||||||
_ => 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(());
|
|
||||||
};
|
|
||||||
|
|
||||||
if deladd == DelAdd::Addition {
|
if deladd == DelAdd::Addition {
|
||||||
self.registered_facets.entry(field_id).and_modify(|count| *count += 1).or_insert(1);
|
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) => {
|
EitherOrBoth::Left(result) => {
|
||||||
let (key, _) = result?;
|
let (key, _) = result?;
|
||||||
facet_search_builder
|
facet_search_builder.register_from_key(DelAdd::Deletion, key)?;
|
||||||
.register_from_key(DelAdd::Deletion, key.left_bound.as_ref())?;
|
|
||||||
}
|
}
|
||||||
EitherOrBoth::Right(result) => {
|
EitherOrBoth::Right(result) => {
|
||||||
let (key, _) = result?;
|
let (key, _) = result?;
|
||||||
facet_search_builder
|
facet_search_builder.register_from_key(DelAdd::Addition, key)?;
|
||||||
.register_from_key(DelAdd::Addition, key.left_bound.as_ref())?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user