feat: Prefer set/del methods instead of set with an Option type

This commit is contained in:
Clément Renault 2019-05-10 11:56:17 +02:00
parent 1f2abce7c3
commit dff81bb161
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE

View File

@ -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)?;
} }
} }