/// Parses the incoming string into an array of attributes for which to return a count. It returns
/// a Vec of attribute names ascociated with their id.
///
/// An error is returned if the array is malformed, or if it contains attributes that are
/// unexisting, or not set as facets.
Parses the incoming string into an array of attributes for which to return a count. It returns
a Vec of attribute names ascociated with their id.

An error is returned if the array is malformed, or if it contains attributes that are
unexisting, or not set as facets.
Parses the incoming string into an array of attributes for which to return a count . It returns a Vec of attribute names ascociated with their id . An error is returned if the array is malformed or if it contains attributes that are unexisting or not set as facets .
fn prepare_facet_list(facets: &str, schema: &Schema, facet_attrs: &[FieldId]) -> Result<Vec<(FieldId, String)>, FacetCountError> {
    let json_array = serde_json::from_str(facets)?;
    match json_array {
        Value::Array(vals) => {
            let wildcard = Value::String("*".to_string());
            if vals.iter().any(|f| f == &wildcard) {
                let attrs = facet_attrs
                    .iter()
                    .filter_map(|&id| schema.name(id).map(|n| (id, n.to_string())))
                    .collect();
                return Ok(attrs);
            }
            let mut field_ids = Vec::with_capacity(facet_attrs.len());
            for facet in vals {
                match facet {
                    Value::String(facet) => {
                        if let Some(id) = schema.id(&facet) {
                            if !facet_attrs.contains(&id) {
                                return Err(FacetCountError::AttributeNotSet(facet));
                            }
                            field_ids.push((id, facet));
                        }
                    }
                    bad_val => return Err(FacetCountError::unexpected_token(bad_val, &["String"])),
                }
            }
            Ok(field_ids)
        }
        bad_val => Err(FacetCountError::unexpected_token(bad_val, &["[String]"]))
    }
}
fn prepare_facet_list ( facets : & str , schema : & Schema , facet_attrs : & [ FieldId ] ) -> Result < Vec < ( FieldId , String ) > , FacetCountError > { let json_array = serde_json :: from_str ( facets ) ? ; match json_array { Value :: Array ( vals ) => { let wildcard = Value :: String ( " " . to_string ( ) ) ; if vals . iter ( ) . any ( | f | f == & wildcard ) { let attrs = facet_attrs . iter ( ) . filter_map ( | & id | schema . name ( id ) . map ( | n | ( id , n . to_string ( ) ) ) ) . collect ( ) ; return Ok ( attrs ) ; } let mut field_ids = Vec :: with_capacity ( facet_attrs . len ( ) ) ; for facet in vals { match facet { Value :: String ( facet ) => { if let Some ( id ) = schema . id ( & facet ) { if ! facet_attrs . contains ( & id ) { return Err ( FacetCountError :: AttributeNotSet ( facet ) ) ; } field_ids . push ( ( id , facet ) ) ; } } bad_val => return Err ( FacetCountError :: unexpected_token ( bad_val , & [ " " ] ) ) , } } Ok ( field_ids ) } bad_val => Err ( FacetCountError :: unexpected_token ( bad_val , & [ " " ] ) ) } }
Parses the incoming string into an array of attributes for which to return a count.
Parses the incoming string into an array of attributes for which to return a count .
facets
&str
schema
&Schema
facet_attrs
&[FieldId]