mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-04 01:46:28 +00:00 
			
		
		
		
	add tests
This commit is contained in:
		
				
					committed by
					
						
						Louis Dureuil
					
				
			
			
				
	
			
			
			
						parent
						
							b2054d3f6c
						
					
				
				
					commit
					0d71c80ba6
				
			@@ -437,12 +437,10 @@ impl<'a> Filter<'a> {
 | 
				
			|||||||
                        Token::new(top_left_point[1].span, Some("180.0".to_string()));
 | 
					                        Token::new(top_left_point[1].span, Some("180.0".to_string()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    let selected_lng = if top_left[1] > bottom_right[1] {
 | 
					                    let selected_lng = if top_left[1] > bottom_right[1] {
 | 
				
			||||||
                        dbg!("test");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        let condition_left = FilterCondition::Condition {
 | 
					                        let condition_left = FilterCondition::Condition {
 | 
				
			||||||
                            fid: geo_lng_token.clone(),
 | 
					                            fid: geo_lng_token.clone(),
 | 
				
			||||||
                            op: Condition::Between {
 | 
					                            op: Condition::Between {
 | 
				
			||||||
                                from: dbg!(top_left_point[1].clone()),
 | 
					                                from: top_left_point[1].clone(),
 | 
				
			||||||
                                to: max_lng_token,
 | 
					                                to: max_lng_token,
 | 
				
			||||||
                            },
 | 
					                            },
 | 
				
			||||||
                        };
 | 
					                        };
 | 
				
			||||||
@@ -455,8 +453,8 @@ impl<'a> Filter<'a> {
 | 
				
			|||||||
                        let condition_right = FilterCondition::Condition {
 | 
					                        let condition_right = FilterCondition::Condition {
 | 
				
			||||||
                            fid: geo_lng_token,
 | 
					                            fid: geo_lng_token,
 | 
				
			||||||
                            op: Condition::Between {
 | 
					                            op: Condition::Between {
 | 
				
			||||||
                                from: dbg!(min_lng_token),
 | 
					                                from: min_lng_token,
 | 
				
			||||||
                                to: dbg!(bottom_right_point[1].clone()),
 | 
					                                to: bottom_right_point[1].clone(),
 | 
				
			||||||
                            },
 | 
					                            },
 | 
				
			||||||
                        };
 | 
					                        };
 | 
				
			||||||
                        let right = Filter { condition: condition_right }.inner_evaluate(
 | 
					                        let right = Filter { condition: condition_right }.inner_evaluate(
 | 
				
			||||||
@@ -465,9 +463,7 @@ impl<'a> Filter<'a> {
 | 
				
			|||||||
                            filterable_fields,
 | 
					                            filterable_fields,
 | 
				
			||||||
                        )?;
 | 
					                        )?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        dbg!(&left);
 | 
					                        left | right
 | 
				
			||||||
                        dbg!(&right);
 | 
					 | 
				
			||||||
                        dbg!(left | right)
 | 
					 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                        let condition_lng = FilterCondition::Condition {
 | 
					                        let condition_lng = FilterCondition::Condition {
 | 
				
			||||||
                            fid: geo_lng_token,
 | 
					                            fid: geo_lng_token,
 | 
				
			||||||
@@ -483,8 +479,6 @@ impl<'a> Filter<'a> {
 | 
				
			|||||||
                        )?
 | 
					                        )?
 | 
				
			||||||
                    };
 | 
					                    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    dbg!(&selected_lng);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    Ok(selected_lat & selected_lng)
 | 
					                    Ok(selected_lat & selected_lng)
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    Err(top_left_point[0].as_external_error(FilterError::AttributeNotFilterable {
 | 
					                    Err(top_left_point[0].as_external_error(FilterError::AttributeNotFilterable {
 | 
				
			||||||
@@ -610,6 +604,12 @@ mod tests {
 | 
				
			|||||||
            "Attribute `_geo` is not filterable. This index does not have configured filterable attributes."
 | 
					            "Attribute `_geo` is not filterable. This index does not have configured filterable attributes."
 | 
				
			||||||
        ));
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let filter = Filter::from_str("_geoBoundingBox((42, 150), (30, 10))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(error.to_string().starts_with(
 | 
				
			||||||
 | 
					            "Attribute `_geo` is not filterable. This index does not have configured filterable attributes."
 | 
				
			||||||
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let filter = Filter::from_str("dog = \"bernese mountain\"").unwrap().unwrap();
 | 
					        let filter = Filter::from_str("dog = \"bernese mountain\"").unwrap().unwrap();
 | 
				
			||||||
        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
        assert!(error.to_string().starts_with(
 | 
					        assert!(error.to_string().starts_with(
 | 
				
			||||||
@@ -632,6 +632,12 @@ mod tests {
 | 
				
			|||||||
            "Attribute `_geo` is not filterable. Available filterable attributes are: `title`."
 | 
					            "Attribute `_geo` is not filterable. Available filterable attributes are: `title`."
 | 
				
			||||||
        ));
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let filter = Filter::from_str("_geoBoundingBox((42, 150), (30, 10))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(error.to_string().starts_with(
 | 
				
			||||||
 | 
					            "Attribute `_geo` is not filterable. Available filterable attributes are: `title`."
 | 
				
			||||||
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let filter = Filter::from_str("name = 12").unwrap().unwrap();
 | 
					        let filter = Filter::from_str("name = 12").unwrap().unwrap();
 | 
				
			||||||
        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
        assert!(error.to_string().starts_with(
 | 
					        assert!(error.to_string().starts_with(
 | 
				
			||||||
@@ -783,6 +789,92 @@ mod tests {
 | 
				
			|||||||
        ));
 | 
					        ));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[test]
 | 
				
			||||||
 | 
					    fn geo_bounding_box_error() {
 | 
				
			||||||
 | 
					        let index = TempIndex::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        index
 | 
				
			||||||
 | 
					            .update_settings(|settings| {
 | 
				
			||||||
 | 
					                settings.set_searchable_fields(vec![S("_geo"), S("price")]); // to keep the fields order
 | 
				
			||||||
 | 
					                settings.set_filterable_fields(hashset! { S("_geo"), S("price") });
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            .unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let rtxn = index.read_txn().unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // geoboundingbox top left coord have a bad latitude
 | 
				
			||||||
 | 
					        let filter =
 | 
				
			||||||
 | 
					            Filter::from_str("_geoBoundingBox((-90.0000001, 150), (30, 10))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(
 | 
				
			||||||
 | 
					            error.to_string().starts_with(
 | 
				
			||||||
 | 
					                "Bad latitude `-90.0000001`. Latitude must be contained between -90 and 90 degrees."
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					            "{}",
 | 
				
			||||||
 | 
					            error.to_string()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // geoboundingbox top left coord have a bad latitude
 | 
				
			||||||
 | 
					        let filter =
 | 
				
			||||||
 | 
					            Filter::from_str("_geoBoundingBox((90.0000001, 150), (30, 10))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(
 | 
				
			||||||
 | 
					            error.to_string().starts_with(
 | 
				
			||||||
 | 
					                "Bad latitude `90.0000001`. Latitude must be contained between -90 and 90 degrees."
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					            "{}",
 | 
				
			||||||
 | 
					            error.to_string()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // geoboundingbox bottom right coord have a bad latitude
 | 
				
			||||||
 | 
					        let filter =
 | 
				
			||||||
 | 
					            Filter::from_str("_geoBoundingBox((30, 10), (-90.0000001, 150))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(error.to_string().contains(
 | 
				
			||||||
 | 
					            "Bad latitude `-90.0000001`. Latitude must be contained between -90 and 90 degrees."
 | 
				
			||||||
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // geoboundingbox bottom right coord have a bad latitude
 | 
				
			||||||
 | 
					        let filter =
 | 
				
			||||||
 | 
					            Filter::from_str("_geoBoundingBox((30, 10), (90.0000001, 150))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(error.to_string().contains(
 | 
				
			||||||
 | 
					            "Bad latitude `90.0000001`. Latitude must be contained between -90 and 90 degrees."
 | 
				
			||||||
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // geoboundingbox top left coord have a bad longitude
 | 
				
			||||||
 | 
					        let filter =
 | 
				
			||||||
 | 
					            Filter::from_str("_geoBoundingBox((-10, 180.000001), (30, 10))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(error.to_string().contains(
 | 
				
			||||||
 | 
					            "Bad longitude `180.000001`. Longitude must be contained between -180 and 180 degrees."
 | 
				
			||||||
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // geoboundingbox top left coord have a bad longitude
 | 
				
			||||||
 | 
					        let filter =
 | 
				
			||||||
 | 
					            Filter::from_str("_geoBoundingBox((-10, -180.000001), (30, 10))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(error.to_string().contains(
 | 
				
			||||||
 | 
					            "Bad longitude `-180.000001`. Longitude must be contained between -180 and 180 degrees."
 | 
				
			||||||
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // geoboundingbox bottom right coord have a bad longitude
 | 
				
			||||||
 | 
					        let filter =
 | 
				
			||||||
 | 
					            Filter::from_str("_geoBoundingBox((30, 10), (-10, -180.000001))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(error.to_string().contains(
 | 
				
			||||||
 | 
					            "Bad longitude `-180.000001`. Longitude must be contained between -180 and 180 degrees."
 | 
				
			||||||
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // geoboundingbox bottom right coord have a bad longitude
 | 
				
			||||||
 | 
					        let filter =
 | 
				
			||||||
 | 
					            Filter::from_str("_geoBoundingBox((30, 10), (-10, 180.000001))").unwrap().unwrap();
 | 
				
			||||||
 | 
					        let error = filter.evaluate(&rtxn, &index).unwrap_err();
 | 
				
			||||||
 | 
					        assert!(error.to_string().contains(
 | 
				
			||||||
 | 
					            "Bad longitude `180.000001`. Longitude must be contained between -180 and 180 degrees."
 | 
				
			||||||
 | 
					        ));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn filter_depth() {
 | 
					    fn filter_depth() {
 | 
				
			||||||
        // generates a big (2 MiB) filter with too much of ORs.
 | 
					        // generates a big (2 MiB) filter with too much of ORs.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user