nested fields

This commit is contained in:
Irevoire 2022-03-23 17:28:41 +01:00 committed by Tamo
parent 4ae7aea3b2
commit 4f3ce6d9cd
No known key found for this signature in database
GPG key ID: 20CD8020AFA88D69
22 changed files with 1197 additions and 367 deletions

View file

@ -49,6 +49,24 @@ impl DocumentsBatchIndex {
pub fn name(&self, id: FieldId) -> Option<&String> {
self.0.get_by_left(&id)
}
pub fn recreate_json(
&self,
document: &obkv::KvReaderU16,
) -> Result<serde_json::Map<String, serde_json::Value>, crate::Error> {
let mut map = serde_json::Map::new();
for (k, v) in document.iter() {
// TODO: TAMO: update the error type
let key =
self.0.get_by_left(&k).ok_or(crate::error::InternalError::DatabaseClosing)?.clone();
let value = serde_json::from_slice::<serde_json::Value>(v)
.map_err(crate::error::InternalError::SerdeJson)?;
map.insert(key, value);
}
Ok(map)
}
}
#[derive(Debug, Serialize, Deserialize)]