Fix facet strings

This commit is contained in:
ManyTheFish 2024-11-13 13:50:10 +01:00 committed by Clément Renault
parent 51b6293738
commit e627e182ce
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F
2 changed files with 13 additions and 14 deletions

View File

@ -364,9 +364,9 @@ impl DocidsSender for FacetDocidsSender<'_> {
pub struct FieldIdDocidFacetSender<'a>(&'a ExtractorSender); pub struct FieldIdDocidFacetSender<'a>(&'a ExtractorSender);
impl FieldIdDocidFacetSender<'_> { impl FieldIdDocidFacetSender<'_> {
pub fn write_facet_string(&self, key: &[u8]) -> StdResult<(), SendError<()>> { pub fn write_facet_string(&self, key: &[u8], value: &[u8]) -> StdResult<(), SendError<()>> {
debug_assert!(FieldDocIdFacetStringCodec::bytes_decode(key).is_ok()); debug_assert!(FieldDocIdFacetStringCodec::bytes_decode(key).is_ok());
let entry = EntryOperation::Write(KeyValueEntry::from_small_key_value(&key, &[])); let entry = EntryOperation::Write(KeyValueEntry::from_small_key_value(&key, &value));
self.0 self.0
.send_db_operation(DbOperation { database: Database::FieldIdDocidFacetStrings, entry }) .send_db_operation(DbOperation { database: Database::FieldIdDocidFacetStrings, entry })
} }

View File

@ -290,22 +290,22 @@ impl<'doc> DelAddFacetValue<'doc> {
sender: &FieldIdDocidFacetSender, sender: &FieldIdDocidFacetSender,
doc_alloc: &Bump, doc_alloc: &Bump,
) -> std::result::Result<(), crossbeam_channel::SendError<()>> { ) -> std::result::Result<(), crossbeam_channel::SendError<()>> {
println!("sending FieldIdDocidFacet data");
let mut count = 0;
let mut buffer = bumpalo::collections::Vec::new_in(doc_alloc); let mut buffer = bumpalo::collections::Vec::new_in(doc_alloc);
for ((fid, value), deladd) in self.strings { for ((fid, value), deladd) in self.strings {
buffer.clear(); if let Ok(s) = std::str::from_utf8(&value) {
buffer.extend_from_slice(&fid.to_be_bytes()); buffer.clear();
buffer.extend_from_slice(&docid.to_be_bytes()); buffer.extend_from_slice(&fid.to_be_bytes());
buffer.extend_from_slice(&value); buffer.extend_from_slice(&docid.to_be_bytes());
match deladd { let normalized = crate::normalize_facet(s);
DelAdd::Deletion => sender.delete_facet_string(&buffer)?, let truncated = truncate_str(&normalized);
DelAdd::Addition => sender.write_facet_string(&buffer)?, buffer.extend_from_slice(truncated.as_bytes());
match deladd {
DelAdd::Deletion => sender.delete_facet_string(&buffer)?,
DelAdd::Addition => sender.write_facet_string(&buffer, &value)?,
}
} }
count += 1;
} }
count = 0;
for ((fid, value), deladd) in self.f64s { for ((fid, value), deladd) in self.f64s {
buffer.clear(); buffer.clear();
buffer.extend_from_slice(&fid.to_be_bytes()); buffer.extend_from_slice(&fid.to_be_bytes());
@ -315,7 +315,6 @@ impl<'doc> DelAddFacetValue<'doc> {
DelAdd::Deletion => sender.delete_facet_f64(&buffer)?, DelAdd::Deletion => sender.delete_facet_f64(&buffer)?,
DelAdd::Addition => sender.write_facet_f64(&buffer)?, DelAdd::Addition => sender.write_facet_f64(&buffer)?,
} }
count += 1;
} }
Ok(()) Ok(())