pub fn records_matching(&self, clause: &Clause, binding: &Binding) -> Result<Vec<Record>> {
        let expanded = clause.substitute(binding)?;
        match expanded {
            // ?e a v => use the VAE index if value type is ref, AVET if indexed, otherwise AEV
            Clause {
                entity: Term::Unbound(_),
                attribute: Term::Bound(a),
                value: Term::Bound(v),
            } => {
                let attr = self.ident_entity(&a).ok_or(format!("invalid attribute: {:?}", a))?;
                let range_start = Record::addition(Entity(0), attr, v.clone(), Entity(0));


                if let Value::Ref(_) = v {
                    // Since the value type is Ref, we can use the VAE index.
                    Ok(
                        self.vae
                            .range_from(range_start)
                            .take_while(|rec| rec.attribute == attr && rec.value == v)
                            .collect()
                    )
                } else if self.schema.is_indexed(attr) {
                    Ok(
                        self.ave
                            .range_from(range_start)
                            .take_while(|rec| rec.attribute == attr && rec.value == v)
                            .collect()
                    )
                } else {
                    Ok(
                        self.aev
                            .range_from(range_start)
                            .take_while(|rec| rec.attribute == attr)
                            .filter(|rec| rec.value == v)
                            .collect()
                    )
                }
            }

            // e a ?v => use the eav index
            Clause {
                entity: Term::Bound(e),
                attribute: Term::Bound(a),
                value: Term::Unbound(_),
            } => {
                match self.ident_entity(&a) {
                    Some(attr) => {
                        // Value::String("") is the lowest-sorted value
                        let range_start =
                            Record::addition(e, attr, Value::String("".into()), Entity(0));
                        Ok(
                            self.eav
                                .range_from(range_start)
                                .take_while(|rec| rec.entity == e && rec.attribute == attr)
                                .collect(),
                        )
                    }
                    _ => return Err("invalid attribute".into()),
                }
            }
            // FIXME: Implement other optimized index use cases? (multiple unknowns?)
            // Fallthrough case: just scan the EAV index. Correct but slow.
            _ => {
                Ok(
                    self.eav
                        .iter()
                        .filter(|f| self.unify(&binding, &clause, &f).is_some())
                        .collect(),
                )
            }
        }
    }
// FIXME: make private
// FIXME: should return a fallible iterator instead of a vec
make private
FIXME: should return a fallible iterator instead of a vec
make private FIXME : should return a fallible iterator instead of a vec
pub fn records_matching(&self, clause: &Clause, binding: &Binding) -> Result<Vec<Record>> {
        let expanded = clause.substitute(binding)?;
        match expanded {
            // ?e a v => use the VAE index if value type is ref, AVET if indexed, otherwise AEV
            Clause {
                entity: Term::Unbound(_),
                attribute: Term::Bound(a),
                value: Term::Bound(v),
            } => {
                let attr = self.ident_entity(&a).ok_or(format!("invalid attribute: {:?}", a))?;
                let range_start = Record::addition(Entity(0), attr, v.clone(), Entity(0));
                if let Value::Ref(_) = v {
                    // Since the value type is Ref, we can use the VAE index.
                    Ok(
                        self.vae
                            .range_from(range_start)
                            .take_while(|rec| rec.attribute == attr && rec.value == v)
                            .collect()
                    )
                } else if self.schema.is_indexed(attr) {
                    Ok(
                        self.ave
                            .range_from(range_start)
                            .take_while(|rec| rec.attribute == attr && rec.value == v)
                            .collect()
                    )
                } else {
                    Ok(
                        self.aev
                            .range_from(range_start)
                            .take_while(|rec| rec.attribute == attr)
                            .filter(|rec| rec.value == v)
                            .collect()
                    )
                }
            }
            // e a ?v => use the eav index
            Clause {
                entity: Term::Bound(e),
                attribute: Term::Bound(a),
                value: Term::Unbound(_),
            } => {
                match self.ident_entity(&a) {
                    Some(attr) => {
                        // Value::String("") is the lowest-sorted value
                        let range_start =
                            Record::addition(e, attr, Value::String("".into()), Entity(0));
                        Ok(
                            self.eav
                                .range_from(range_start)
                                .take_while(|rec| rec.entity == e && rec.attribute == attr)
                                .collect(),
                        )
                    }
                    _ => return Err("invalid attribute".into()),
                }
            }
            // FIXME: Implement other optimized index use cases? (multiple unknowns?)
            // Fallthrough case: just scan the EAV index. Correct but slow.
            _ => {
                Ok(
                    self.eav
                        .iter()
                        .filter(|f| self.unify(&binding, &clause, &f).is_some())
                        .collect(),
                )
            }
        }
    }
pub fn records_matching ( & self , clause : & Clause , binding : & Binding ) -> Result < Vec < Record > > { let expanded = clause . substitute ( binding ) ? ; match expanded { // ?e a v => use the VAE index if value type is ref, AVET if indexed, otherwise AEV Clause { entity : Term :: Unbound ( _ ) , attribute : Term :: Bound ( a ) , value : Term :: Bound ( v ) , } => { let attr = self . ident_entity ( & a ) . ok_or ( format ! ( " " a ) ) ? ; let range_start = Record :: addition ( Entity ( 0 ) , attr , v . clone ( ) , Entity ( 0 ) ) ; if let Value :: Ref ( _ ) = v { // Since the value type is Ref, we can use the VAE index. Ok ( self . vae . range_from ( range_start ) . take_while ( | rec | rec . attribute == attr && rec . value == v ) . collect ( ) ) } else if self . schema . is_indexed ( attr ) { Ok ( self . ave . range_from ( range_start ) . take_while ( | rec | rec . attribute == attr && rec . value == v ) . collect ( ) ) } else { Ok ( self . aev . range_from ( range_start ) . take_while ( | rec | rec . attribute == attr ) . filter ( | rec | rec . value == v ) . collect ( ) ) } } // e a ?v => use the eav index Clause { entity : Term :: Bound ( e ) , attribute : Term :: Bound ( a ) , value : Term :: Unbound ( _ ) , } => { match self . ident_entity ( & a ) { Some ( attr ) => { // Value::String("") is the lowest-sorted value let range_start = Record :: addition ( e , attr , Value :: String ( " " . into ( ) ) , Entity ( 0 ) ) ; Ok ( self . eav . range_from ( range_start ) . take_while ( | rec | rec . entity == e && rec . attribute == attr ) . collect ( ) , ) } _ => return Err ( " " . into ( ) ) , } } // FIXME: Implement other optimized index use cases? (multiple unknowns?) // Fallthrough case: just scan the EAV index. Correct but slow. _ => { Ok ( self . eav . iter ( ) . filter ( | f | self . unify ( & binding , & clause , & f ) . is_some ( ) ) . collect ( ) , ) } } }
FIXME: make private
FIXME: should return a fallible iterator instead of a vec
FIXME : make private FIXME : should return a fallible iterator instead of a vec
&self
clause
&Clause
binding
&Binding
&self
clause
&Clause
binding
&Binding