fn filter_records()

in components/search/src/filter.rs [186:247]


    fn filter_records(
        &self,
        user_environment: &mut SearchUserEnvironment,
        overrides: Option<Vec<JSONOverridesRecord>>,
    ) -> Result<FilterRecordsResult, Error> {
        let mut available_locales = Vec::new();
        for record in self {
            if let Some(val) = record.fields.get("recordType") {
                if *val == "availableLocales" {
                    let stringified = serde_json::to_string(&record.fields)?;
                    let locales_record: Option<JSONAvailableLocalesRecord> =
                        serde_json::from_str(&stringified)?;
                    available_locales = locales_record.unwrap().locales;
                }
            }
        }
        negotiate_languages(user_environment, &available_locales);

        let mut engines = Vec::new();
        let mut default_engines_record = None;
        let mut engine_orders_record = None;

        for record in self {
            // TODO: Bug 1947241 - Find a way to avoid having to serialise the records
            // back to strings and then deserialise them into the records that we want.
            let stringified = serde_json::to_string(&record.fields)?;
            match record.fields.get("recordType") {
                Some(val) if *val == "engine" => {
                    let engine_config: Option<JSONEngineRecord> =
                        serde_json::from_str(&stringified)?;
                    if let Some(engine_config) = engine_config {
                        let result =
                            maybe_extract_engine_config(user_environment, Box::new(engine_config));
                        engines.extend(result);
                    }
                }
                Some(val) if *val == "defaultEngines" => {
                    default_engines_record = serde_json::from_str(&stringified)?;
                }
                Some(val) if *val == "engineOrders" => {
                    engine_orders_record = serde_json::from_str(&stringified)?;
                }
                Some(val) if *val == "availableLocales" => {
                    // Handled above
                }
                // These cases are acceptable - we expect the potential for new
                // record types/options so that we can be flexible.
                Some(_val) => {}
                None => {}
            }
        }

        if let Some(overrides_data) = &overrides {
            apply_overrides(&mut engines, overrides_data);
        }

        Ok(FilterRecordsResult {
            engines,
            default_engines_record,
            engine_orders_record,
        })
    }