Deserialize documents ids into JSON Values on deletion

This commit is contained in:
Clément Renault 2021-02-13 13:57:53 +01:00 committed by Kerollmops
parent b3776598d8
commit 69acdd437e
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -1,6 +1,8 @@
use anyhow::anyhow;
use fst::IntoStreamer; use fst::IntoStreamer;
use heed::types::ByteSlice; use heed::types::ByteSlice;
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
use serde_json::Value;
use crate::facet::FacetType; use crate::facet::FacetType;
use crate::{Index, BEU32, SmallString32, ExternalDocumentsIds}; use crate::{Index, BEU32, SmallString32, ExternalDocumentsIds};
@ -95,7 +97,11 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
let mut iter = documents.range_mut(self.wtxn, &(key..=key))?; let mut iter = documents.range_mut(self.wtxn, &(key..=key))?;
if let Some((_key, obkv)) = iter.next().transpose()? { if let Some((_key, obkv)) = iter.next().transpose()? {
if let Some(content) = obkv.get(id_field) { if let Some(content) = obkv.get(id_field) {
let external_id: SmallString32 = serde_json::from_slice(content).unwrap(); let external_id = match serde_json::from_slice(content).unwrap() {
Value::String(string) => SmallString32::from(string.as_str()),
Value::Number(number) => SmallString32::from(number.to_string()),
_ => return Err(anyhow!("documents ids must be either strings or numbers")),
};
external_ids.push(external_id); external_ids.push(external_id);
} }
iter.del_current()?; iter.del_current()?;