facets: Handle boolean and skip empty strings

This commit is contained in:
Louis Dureuil 2024-11-20 10:51:43 +01:00 committed by Clément Renault
parent 477077bdc2
commit ca779c21f9
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -207,7 +207,7 @@ impl FacetedDocidsExtractor {
} }
// String // String
// key: fid - level - truncated_string // key: fid - level - truncated_string
Value::String(s) => { Value::String(s) if !s.is_empty() => {
let mut string = BVec::new_in(doc_alloc); let mut string = BVec::new_in(doc_alloc);
string.extend_from_slice(s.as_bytes()); string.extend_from_slice(s.as_bytes());
facet_fn(del_add_facet_value, fid, string, FacetKind::String); facet_fn(del_add_facet_value, fid, string, FacetKind::String);
@ -221,6 +221,20 @@ impl FacetedDocidsExtractor {
buffer.extend_from_slice(truncated.as_bytes()); buffer.extend_from_slice(truncated.as_bytes());
cache_fn(cached_sorter, &buffer, docid) cache_fn(cached_sorter, &buffer, docid)
} }
/// Bool is handled as a string
Value::Bool(b) => {
let b = if *b { "true" } else { "false" };
let mut string = BVec::new_in(doc_alloc);
string.extend_from_slice(b.as_bytes());
facet_fn(del_add_facet_value, fid, string, FacetKind::String);
buffer.clear();
buffer.push(FacetKind::String as u8);
buffer.extend_from_slice(&fid.to_be_bytes());
buffer.push(0); // level 0
buffer.extend_from_slice(b.as_bytes());
cache_fn(cached_sorter, &buffer, docid)
}
// Null // Null
// key: fid // key: fid
Value::Null if depth == perm_json_p::Depth::OnBaseKey => { Value::Null if depth == perm_json_p::Depth::OnBaseKey => {
@ -237,6 +251,12 @@ impl FacetedDocidsExtractor {
buffer.extend_from_slice(&fid.to_be_bytes()); buffer.extend_from_slice(&fid.to_be_bytes());
cache_fn(cached_sorter, &buffer, docid) cache_fn(cached_sorter, &buffer, docid)
} }
Value::String(_) => {
buffer.clear();
buffer.push(FacetKind::Empty as u8);
buffer.extend_from_slice(&fid.to_be_bytes());
cache_fn(cached_sorter, &buffer, docid)
}
Value::Object(o) if o.is_empty() && depth == perm_json_p::Depth::OnBaseKey => { Value::Object(o) if o.is_empty() && depth == perm_json_p::Depth::OnBaseKey => {
buffer.clear(); buffer.clear();
buffer.push(FacetKind::Empty as u8); buffer.push(FacetKind::Empty as u8);
@ -244,7 +264,6 @@ impl FacetedDocidsExtractor {
cache_fn(cached_sorter, &buffer, docid) cache_fn(cached_sorter, &buffer, docid)
} }
// Otherwise, do nothing // Otherwise, do nothing
/// TODO: What about Value::Bool?
_ => Ok(()), _ => Ok(()),
} }
} }