Repository: meilisearch/meilisearch
File: milli/src/search/facet/filter.rs (Rust)

Code before:
        facet_range_search::find_docids_of_facet_within_bounds::<OrderedF64Codec>(
            rtxn, db, field_id, &left, &right, universe, output,
        )?;

        Ok(())
    }

    fn inner_evaluate(
        &self,
        rtxn: &heed::RoTxn,
        index: &Index,
        filterable_fields: &HashSet<String>,
        universe: Option<&RoaringBitmap>,
    ) -> Result<RoaringBitmap> {
        match &self.condition {
            FilterCondition::Not(f) => {
                // TODO improve the documents_ids to also support intersections at deserialize time.
                let all_ids = index.documents_ids(rtxn)?;
                let selected = Self::inner_evaluate(
                    &(f.as_ref().clone()).into(),
                    rtxn,
                    index,
                    filterable_fields,
                    universe,
                )?;
                Ok(all_ids - selected)
            }
            FilterCondition::In { fid, els } => {
                if crate::is_faceted(fid.value(), filterable_fields) {
                    let field_ids_map = index.fields_ids_map(rtxn)?;

                    if let Some(fid) = field_ids_map.id(fid.value()) {
                        let mut bitmap = RoaringBitmap::new();

                        for el in els {
                            let op = Condition::Equal(el.clone());
                            let el_bitmap =
                                Self::evaluate_operator(rtxn, index, fid, universe, &op)?;
                            bitmap |= el_bitmap;
                        }
                        Ok(bitmap)
                    } else {
                        Ok(RoaringBitmap::new())
                    }
                } else {
                    Err(fid.as_external_error(FilterError::AttributeNotFilterable {
                        attribute: fid.value(),
                        filterable_fields: filterable_fields.clone(),
                    }))?
                }
            }

Review comment (suggestion):
I think `all_ids` here is simply the universe or this call to `documents_ids` if no universe has been given.

Code after:
        facet_range_search::find_docids_of_facet_within_bounds::<OrderedF64Codec>(
            rtxn, db, field_id, &left, &right, universe, output,
        )?;

        Ok(())
    }

    fn inner_evaluate(
        &self,
        rtxn: &heed::RoTxn,
        index: &Index,
        filterable_fields: &HashSet<String>,
        universe: Option<&RoaringBitmap>,
    ) -> Result<RoaringBitmap> {
        if universe.map_or(false, |u| u.is_empty()) {
            return Ok(RoaringBitmap::new());
        }

        match &self.condition {
            FilterCondition::Not(f) => {
                let selected = Self::inner_evaluate(
                    &(f.as_ref().clone()).into(),
                    rtxn,
                    index,
                    filterable_fields,
                    universe,
                )?;
                match universe {
                    Some(universe) => Ok(universe - selected),
                    None => {
                        let all_ids = index.documents_ids(rtxn)?;
                        Ok(all_ids - selected)
                    }
                }
            }
            FilterCondition::In { fid, els } => {
                if crate::is_faceted(fid.value(), filterable_fields) {
                    let field_ids_map = index.fields_ids_map(rtxn)?;
                    if let Some(fid) = field_ids_map.id(fid.value()) {
                        els.iter()
                            .map(|el| Condition::Equal(el.clone()))
                            .map(|op| Self::evaluate_operator(rtxn, index, fid, universe, &op))
                            .union()
                    } else {
                        Ok(RoaringBitmap::new())
                    }
                } else {
                    Err(fid.as_external_error(FilterError::AttributeNotFilterable {
                        attribute: fid.value(),
                        filterable_fields: filterable_fields.clone(),
                    }))?