mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-26 06:30:05 +01:00
feat: Prefer set/del methods instead of set with an Option type
This commit is contained in:
parent
1f2abce7c3
commit
dff81bb161
@ -324,20 +324,15 @@ impl AttrsWords {
|
|||||||
DocumentAttrsWordsIter(self.0.range(start..=end))
|
DocumentAttrsWordsIter(self.0.range(start..=end))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_attr_words(
|
pub fn set_attr_words(&self, id: DocumentId, attr: SchemaAttr, words: &fst::Set) -> Result<(), Error> {
|
||||||
&self,
|
|
||||||
id: DocumentId,
|
|
||||||
attr: SchemaAttr,
|
|
||||||
words: Option<&fst::Set>,
|
|
||||||
) -> Result<(), Error>
|
|
||||||
{
|
|
||||||
let key = DocumentAttrKey::new(id, attr).to_be_bytes();
|
let key = DocumentAttrKey::new(id, attr).to_be_bytes();
|
||||||
|
self.0.set(key, words.as_fst().as_bytes())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
match words {
|
pub fn del_attr_words(&self, id: DocumentId, attr: SchemaAttr) -> Result<(), Error> {
|
||||||
Some(words) => self.0.set(key, words.as_fst().as_bytes())?,
|
let key = DocumentAttrKey::new(id, attr).to_be_bytes();
|
||||||
None => self.0.del(key)?,
|
self.0.del(key)?;
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -582,7 +577,7 @@ impl<'a> DocumentsAddition<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for ((id, attr), words) in docs_attrs_words {
|
for ((id, attr), words) in docs_attrs_words {
|
||||||
attrs_words.set_attr_words(id, attr, Some(&words))?;
|
attrs_words.set_attr_words(id, attr, &words)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let delta_words = delta_words_builder
|
let delta_words = delta_words_builder
|
||||||
@ -681,6 +676,7 @@ impl<'a> DocumentsDeletion<'a> {
|
|||||||
|
|
||||||
for (id, attr) in attrs.into_vec() {
|
for (id, attr) in attrs.into_vec() {
|
||||||
documents.del_document_field(id, attr)?;
|
documents.del_document_field(id, attr)?;
|
||||||
|
attrs_words.del_attr_words(id, attr)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user