Add a simple test to the FacetCondition from_array method

This commit is contained in:
Kerollmops 2020-12-21 19:36:14 +01:00
parent cb5e57e2dd
commit afa86d8a45
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -717,4 +717,35 @@ mod tests {
); );
assert_eq!(condition, expected); assert_eq!(condition, expected);
} }
#[test]
fn from_array() {
let path = tempfile::tempdir().unwrap();
let mut options = EnvOpenOptions::new();
options.map_size(10 * 1024 * 1024); // 10 MB
let index = Index::new(options, &path).unwrap();
// Set the faceted fields to be the channel.
let mut wtxn = index.write_txn().unwrap();
let mut builder = Settings::new(&mut wtxn, &index);
builder.set_searchable_fields(vec!["channel".into(), "timestamp".into()]); // to keep the fields order
builder.set_faceted_fields(hashmap!{
"channel".into() => "string".into(),
"timestamp".into() => "integer".into(),
});
builder.execute(|_| ()).unwrap();
wtxn.commit().unwrap();
// Test that the facet condition is correctly generated.
let rtxn = index.read_txn().unwrap();
let condition = FacetCondition::from_array(
&rtxn, &index,
vec![Either::Right("channel:gotaga"), Either::Left(vec!["timestamp:44", "channel:-ponce"])],
).unwrap().unwrap();
let expected = FacetCondition::from_str(
&rtxn, &index,
"channel = gotaga AND (timestamp = 44 OR channel != ponce)",
).unwrap();
assert_eq!(condition, expected);
}
} }