Change the filterableAttributes setting API

**Changes:**
The filterableAttributes type has been changed from a `BTreeSet<String>` to a `Vec<FilterableAttributesRule>`,
Which is a list of rules defining patterns to match the documents' fields and a set of feature to apply on the matching fields.
The rule order given by the user is now an important information, the features applied on a filterable field will be chosen based on the rule order as we do for the LocalizedAttributesRules.
This means that the list will not be reordered anymore and will keep the user defined order,
moreover, if there are any duplicates, they will not be de-duplicated anymore.

**Impact:**
- Settings API
- the database format of the filterable attributes changed
- may impact the LocalizedAttributesRules due to the AttributePatterns factorization
- OpenAPI generator
This commit is contained in:
ManyTheFish 2025-03-03 10:22:02 +01:00
parent c63c25a9a2
commit 0200c65ebf
10 changed files with 386 additions and 79 deletions

View file

@ -876,11 +876,11 @@ impl Index {
/* filterable fields */
/// Writes the filterable fields names in the database.
pub(crate) fn put_filterable_fields(
/// Writes the filterable attributes rules in the database.
pub(crate) fn put_filterable_attributes_rules(
&self,
wtxn: &mut RwTxn<'_>,
fields: &HashSet<String>,
#[allow(clippy::ptr_arg)] fields: &Vec<FilterableAttributesRule>,
) -> heed::Result<()> {
self.main.remap_types::<Str, SerdeJson<_>>().put(
wtxn,
@ -889,13 +889,19 @@ impl Index {
)
}
/// Deletes the filterable fields ids in the database.
pub(crate) fn delete_filterable_fields(&self, wtxn: &mut RwTxn<'_>) -> heed::Result<bool> {
/// Deletes the filterable attributes rules in the database.
pub(crate) fn delete_filterable_attributes_rules(
&self,
wtxn: &mut RwTxn<'_>,
) -> heed::Result<bool> {
self.main.remap_key_type::<Str>().delete(wtxn, main_key::FILTERABLE_FIELDS_KEY)
}
/// Returns the filterable fields names.
pub fn filterable_fields(&self, rtxn: &RoTxn<'_>) -> heed::Result<HashSet<String>> {
/// Returns the filterable attributes rules.
pub fn filterable_attributes_rules(
&self,
rtxn: &RoTxn<'_>,
) -> heed::Result<Vec<FilterableAttributesRule>> {
Ok(self
.main
.remap_types::<Str, SerdeJson<_>>()
@ -903,21 +909,6 @@ impl Index {
.unwrap_or_default())
}
/// Identical to `filterable_fields`, but returns ids instead.
pub fn filterable_fields_ids(&self, rtxn: &RoTxn<'_>) -> Result<HashSet<FieldId>> {
let fields = self.filterable_fields(rtxn)?;
let fields_ids_map = self.fields_ids_map(rtxn)?;
let mut fields_ids = HashSet::new();
for name in fields {
if let Some(field_id) = fields_ids_map.id(&name) {
fields_ids.insert(field_id);
}
}
Ok(fields_ids)
}
/* sortable fields */
/// Writes the sortable fields names in the database.