mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-04 09:56:28 +00:00 
			
		
		
		
	Improve the testing of the filters
This commit is contained in:
		@@ -212,10 +212,22 @@ fn execute_filter(filter: &str, document: &TestDocument) -> Option<String> {
 | 
			
		||||
    } else if matches!(filter, "opt1.opt2 IS NULL") {
 | 
			
		||||
        if document.opt1opt2.as_ref().map_or(false, |v| v.is_null()) {
 | 
			
		||||
            id = Some(document.id.clone());
 | 
			
		||||
        } else if let Some(opt1) = &document.opt1 {
 | 
			
		||||
            if !opt1.is_null() {
 | 
			
		||||
                id = contains_null_rec(opt1, "opt2").then(|| document.id.clone());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } else if matches!(filter, "opt1 IS EMPTY" | "NOT opt1 IS NOT EMPTY") {
 | 
			
		||||
        id = document
 | 
			
		||||
            .opt1
 | 
			
		||||
            .as_ref()
 | 
			
		||||
            .map_or(false, |v| is_empty_value(v))
 | 
			
		||||
            .then(|| document.id.clone());
 | 
			
		||||
    } else if matches!(filter, "NOT opt1 IS EMPTY" | "opt1 IS NOT EMPTY") {
 | 
			
		||||
        id = document
 | 
			
		||||
            .opt1
 | 
			
		||||
            .as_ref()
 | 
			
		||||
            .map_or(true, |v| !is_empty_value(v))
 | 
			
		||||
            .then(|| document.id.clone());
 | 
			
		||||
    } else if matches!(filter, "opt1.opt2 IS EMPTY") {
 | 
			
		||||
        if document.opt1opt2.as_ref().map_or(false, |v| is_empty_value(v)) {
 | 
			
		||||
            id = Some(document.id.clone());
 | 
			
		||||
        }
 | 
			
		||||
    } else if matches!(
 | 
			
		||||
        filter,
 | 
			
		||||
@@ -230,6 +242,15 @@ fn execute_filter(filter: &str, document: &TestDocument) -> Option<String> {
 | 
			
		||||
    id
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn is_empty_value(v: &serde_json::Value) -> bool {
 | 
			
		||||
    match v {
 | 
			
		||||
        serde_json::Value::String(s) => s.is_empty(),
 | 
			
		||||
        serde_json::Value::Array(a) => a.is_empty(),
 | 
			
		||||
        serde_json::Value::Object(o) => o.is_empty(),
 | 
			
		||||
        _ => false,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn contains_key_rec(v: &serde_json::Value, key: &str) -> bool {
 | 
			
		||||
    match v {
 | 
			
		||||
        serde_json::Value::Array(v) => {
 | 
			
		||||
@@ -252,28 +273,6 @@ pub fn contains_key_rec(v: &serde_json::Value, key: &str) -> bool {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn contains_null_rec(v: &serde_json::Value, key: &str) -> bool {
 | 
			
		||||
    match v {
 | 
			
		||||
        serde_json::Value::Object(v) => {
 | 
			
		||||
            for (k, v) in v.iter() {
 | 
			
		||||
                if k == key && v.is_null() || contains_null_rec(v, key) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            false
 | 
			
		||||
        }
 | 
			
		||||
        serde_json::Value::Array(v) => {
 | 
			
		||||
            for v in v.iter() {
 | 
			
		||||
                if contains_null_rec(v, key) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            false
 | 
			
		||||
        }
 | 
			
		||||
        _ => false,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn expected_filtered_ids(filters: Vec<Either<Vec<&str>, &str>>) -> HashSet<String> {
 | 
			
		||||
    let dataset: Vec<TestDocument> =
 | 
			
		||||
        serde_json::Deserializer::from_str(CONTENT).into_iter().map(|r| r.unwrap()).collect();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user