From afa86d8a45f20e1e4f1a88d7401ade0f4b6358e8 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Mon, 21 Dec 2020 19:36:14 +0100 Subject: [PATCH] Add a simple test to the FacetCondition from_array method --- src/search/facet/facet_condition.rs | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/search/facet/facet_condition.rs b/src/search/facet/facet_condition.rs index ce4a22119..762134759 100644 --- a/src/search/facet/facet_condition.rs +++ b/src/search/facet/facet_condition.rs @@ -717,4 +717,35 @@ mod tests { ); 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); + } }