mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
Revert metadata creation when computing facet search and distinct
This commit is contained in:
parent
b12ffd1356
commit
abef655849
6 changed files with 45 additions and 156 deletions
|
@ -10,9 +10,7 @@ use roaring::RoaringBitmap;
|
|||
use tracing::error;
|
||||
|
||||
use crate::error::UserError;
|
||||
use crate::filterable_attributes_rules::{
|
||||
filtered_matching_field_names, is_field_facet_searchable,
|
||||
};
|
||||
use crate::filterable_attributes_rules::{filtered_matching_patterns, matching_features};
|
||||
use crate::heed_codec::facet::{FacetGroupKey, FacetGroupValue};
|
||||
use crate::search::build_dfa;
|
||||
use crate::{DocumentId, FieldId, OrderBy, Result, Search};
|
||||
|
@ -77,37 +75,27 @@ impl<'a> SearchForFacetValues<'a> {
|
|||
let rtxn = self.search_query.rtxn;
|
||||
|
||||
let filterable_attributes_rules = index.filterable_attributes_rules(rtxn)?;
|
||||
let fields_ids_map = index.fields_ids_map_with_metadata(rtxn)?;
|
||||
let fid = match fields_ids_map.id_with_metadata(&self.facet) {
|
||||
Some((fid, metadata))
|
||||
if metadata
|
||||
.filterable_attributes_features(&filterable_attributes_rules)
|
||||
.is_facet_searchable() =>
|
||||
{
|
||||
fid
|
||||
}
|
||||
// we return an empty list of results when the attribute has been
|
||||
// set as filterable but no document contains this field (yet).
|
||||
None if is_field_facet_searchable(&self.facet, &filterable_attributes_rules) => {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
// we return an error when the attribute is not facet searchable
|
||||
_otherwise => {
|
||||
let matching_field_names = filtered_matching_field_names(
|
||||
&filterable_attributes_rules,
|
||||
&fields_ids_map,
|
||||
&|features| features.is_facet_searchable(),
|
||||
);
|
||||
let (valid_fields, hidden_fields) =
|
||||
index.remove_hidden_fields(rtxn, matching_field_names)?;
|
||||
if !matching_features(&self.facet, &filterable_attributes_rules)
|
||||
.map_or(false, |(_, features)| features.is_facet_searchable())
|
||||
{
|
||||
let matching_field_names =
|
||||
filtered_matching_patterns(&filterable_attributes_rules, &|features| {
|
||||
features.is_facet_searchable()
|
||||
});
|
||||
let (valid_patterns, hidden_fields) =
|
||||
index.remove_hidden_fields(rtxn, matching_field_names)?;
|
||||
|
||||
return Err(UserError::InvalidFacetSearchFacetName {
|
||||
field: self.facet.clone(),
|
||||
valid_fields,
|
||||
hidden_fields,
|
||||
}
|
||||
.into());
|
||||
return Err(UserError::InvalidFacetSearchFacetName {
|
||||
field: self.facet.clone(),
|
||||
valid_patterns,
|
||||
hidden_fields,
|
||||
}
|
||||
.into());
|
||||
};
|
||||
|
||||
let fields_ids_map = index.fields_ids_map(rtxn)?;
|
||||
let Some(fid) = fields_ids_map.id(&self.facet) else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
|
||||
let fst = match self.search_query.index.facet_id_string_fst.get(rtxn, &fid)? {
|
||||
|
|
|
@ -9,7 +9,7 @@ use roaring::bitmap::RoaringBitmap;
|
|||
pub use self::facet::{FacetDistribution, Filter, OrderBy, DEFAULT_VALUES_PER_FACET};
|
||||
pub use self::new::matches::{FormatOptions, MatchBounds, MatcherBuilder, MatchingWords};
|
||||
use self::new::{execute_vector_search, PartialSearchResult};
|
||||
use crate::filterable_attributes_rules::{filtered_matching_field_names, is_field_filterable};
|
||||
use crate::filterable_attributes_rules::{filtered_matching_patterns, matching_features};
|
||||
use crate::score_details::{ScoreDetails, ScoringStrategy};
|
||||
use crate::vector::Embedder;
|
||||
use crate::{
|
||||
|
@ -190,20 +190,20 @@ impl<'a> Search<'a> {
|
|||
if let Some(distinct) = &self.distinct {
|
||||
let filterable_fields = ctx.index.filterable_attributes_rules(ctx.txn)?;
|
||||
// check if the distinct field is in the filterable fields
|
||||
if !is_field_filterable(distinct, &filterable_fields) {
|
||||
if !matching_features(distinct, &filterable_fields)
|
||||
.map_or(false, |(_, features)| features.is_filterable())
|
||||
{
|
||||
// if not, remove the hidden fields from the filterable fields to generate the error message
|
||||
let fields_ids_map = ctx.index.fields_ids_map_with_metadata(ctx.txn)?;
|
||||
let matching_field_names = filtered_matching_field_names(
|
||||
&filterable_fields,
|
||||
&fields_ids_map,
|
||||
&|features| features.is_filterable(),
|
||||
);
|
||||
let (valid_fields, hidden_fields) =
|
||||
ctx.index.remove_hidden_fields(ctx.txn, matching_field_names)?;
|
||||
let matching_patterns =
|
||||
filtered_matching_patterns(&filterable_fields, &|features| {
|
||||
features.is_filterable()
|
||||
});
|
||||
let (valid_patterns, hidden_fields) =
|
||||
ctx.index.remove_hidden_fields(ctx.txn, matching_patterns)?;
|
||||
// and return the error
|
||||
return Err(Error::UserError(UserError::InvalidDistinctAttribute {
|
||||
field: distinct.clone(),
|
||||
valid_fields,
|
||||
valid_patterns,
|
||||
hidden_fields,
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue