From 0b061f1e7090e62d1f7b52bd434ac389831ecf7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 4 Sep 2024 17:40:24 +0200 Subject: [PATCH] Introduce the FieldIdFacetIsEmptyDocidsExtractor --- milli/src/update/new/extract/faceted/mod.rs | 32 ++++++++++++++++++++- milli/src/update/new/indexer/mod.rs | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/milli/src/update/new/extract/faceted/mod.rs b/milli/src/update/new/extract/faceted/mod.rs index b230549c1..e3c89b0e4 100644 --- a/milli/src/update/new/extract/faceted/mod.rs +++ b/milli/src/update/new/extract/faceted/mod.rs @@ -186,7 +186,6 @@ impl FacetedExtractor for FieldIdFacetNumberDocidsExtractor { } } -/// TODO It doesn't keep the original string in the value pub struct FieldIdFacetStringDocidsExtractor; impl FacetedExtractor for FieldIdFacetStringDocidsExtractor { fn attributes_to_extract<'a>(rtxn: &'a RoTxn, index: &'a Index) -> Result> { @@ -211,6 +210,37 @@ impl FacetedExtractor for FieldIdFacetStringDocidsExtractor { } } +// Extract fieldid facet isempty docids +// Extract fieldid facet isnull docids +// Extract fieldid facet exists docids + +pub struct FieldIdFacetIsEmptyDocidsExtractor; +impl FacetedExtractor for FieldIdFacetIsEmptyDocidsExtractor { + fn attributes_to_extract<'a>(rtxn: &'a RoTxn, index: &'a Index) -> Result> { + index.user_defined_faceted_fields(rtxn) + } + + fn build_key<'b>( + field_id: FieldId, + value: &Value, + output: &'b mut Vec, + ) -> Option<&'b [u8]> { + let is_empty = match value { + Value::Null | Value::Bool(_) | Value::Number(_) => false, + Value::String(s) => s.is_empty(), + Value::Array(a) => a.is_empty(), + Value::Object(o) => o.is_empty(), + }; + + if is_empty { + output.extend_from_slice(&field_id.to_be_bytes()); + Some(&*output) + } else { + None + } + } +} + pub fn extract_document_facets( attributes_to_extract: &[&str], obkv: &KvReaderFieldId, diff --git a/milli/src/update/new/indexer/mod.rs b/milli/src/update/new/indexer/mod.rs index 21e28fc84..ed42c03b1 100644 --- a/milli/src/update/new/indexer/mod.rs +++ b/milli/src/update/new/indexer/mod.rs @@ -131,7 +131,9 @@ where // Extract fieldid docid facet number // Extract fieldid docid facet string // Extract facetid string fst + // Extract facetid normalized string strings + // TODO Inverted Indexes again // Extract fieldid facet isempty docids // Extract fieldid facet isnull docids // Extract fieldid facet exists docids