From bc51d3a91842f1d173be74a9a0458a906234e823 Mon Sep 17 00:00:00 2001 From: Kushal Kumar Date: Wed, 18 Dec 2024 02:18:57 +0530 Subject: [PATCH 1/2] refactor: remove obsolete test code Signed-off-by: Kushal Kumar --- crates/meilisearch/src/search/mod.rs | 118 +-------------------------- 1 file changed, 1 insertion(+), 117 deletions(-) diff --git a/crates/meilisearch/src/search/mod.rs b/crates/meilisearch/src/search/mod.rs index 8f55e0faf..1c8fbbe0f 100644 --- a/crates/meilisearch/src/search/mod.rs +++ b/crates/meilisearch/src/search/mod.rs @@ -1901,120 +1901,4 @@ fn parse_filter_array(arr: &[Value]) -> Result, MeilisearchHttpEr } Ok(Filter::from_array(ands)?) -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_insert_geo_distance() { - let value: Document = serde_json::from_str( - r#"{ - "_geo": { - "lat": 50.629973371633746, - "lng": 3.0569447399419567 - }, - "city": "Lille", - "id": "1" - }"#, - ) - .unwrap(); - - let sorters = &["_geoPoint(50.629973371633746,3.0569447399419567):desc".to_string()]; - let mut document = value.clone(); - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), Some(&json!(0))); - - let sorters = &["_geoPoint(50.629973371633746, 3.0569447399419567):asc".to_string()]; - let mut document = value.clone(); - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), Some(&json!(0))); - - let sorters = - &["_geoPoint( 50.629973371633746 , 3.0569447399419567 ):desc".to_string()]; - let mut document = value.clone(); - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), Some(&json!(0))); - - let sorters = &[ - "prix:asc", - "villeneuve:desc", - "_geoPoint(50.629973371633746, 3.0569447399419567):asc", - "ubu:asc", - ] - .map(|s| s.to_string()); - let mut document = value.clone(); - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), Some(&json!(0))); - - // only the first geoPoint is used to compute the distance - let sorters = &[ - "chien:desc", - "_geoPoint(50.629973371633746, 3.0569447399419567):asc", - "pangolin:desc", - "_geoPoint(100.0, -80.0):asc", - "chat:asc", - ] - .map(|s| s.to_string()); - let mut document = value.clone(); - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), Some(&json!(0))); - - // there was no _geoPoint so nothing is inserted in the document - let sorters = &["chien:asc".to_string()]; - let mut document = value; - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), None); - } - - #[test] - fn test_insert_geo_distance_with_coords_as_string() { - let value: Document = serde_json::from_str( - r#"{ - "_geo": { - "lat": "50", - "lng": 3 - } - }"#, - ) - .unwrap(); - - let sorters = &["_geoPoint(50,3):desc".to_string()]; - let mut document = value.clone(); - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), Some(&json!(0))); - - let value: Document = serde_json::from_str( - r#"{ - "_geo": { - "lat": "50", - "lng": "3" - }, - "id": "1" - }"#, - ) - .unwrap(); - - let sorters = &["_geoPoint(50,3):desc".to_string()]; - let mut document = value.clone(); - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), Some(&json!(0))); - - let value: Document = serde_json::from_str( - r#"{ - "_geo": { - "lat": 50, - "lng": "3" - }, - "id": "1" - }"#, - ) - .unwrap(); - - let sorters = &["_geoPoint(50,3):desc".to_string()]; - let mut document = value.clone(); - insert_geo_distance(sorters, &mut document); - assert_eq!(document.get("_geoDistance"), Some(&json!(0))); - } -} +} \ No newline at end of file From ba27a09efe73a097a8ec656d0cf5ba0521821656 Mon Sep 17 00:00:00 2001 From: Kushal Kumar Date: Wed, 18 Dec 2024 02:28:02 +0530 Subject: [PATCH 2/2] refactor: fmt Signed-off-by: Kushal Kumar --- crates/meilisearch/src/search/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/meilisearch/src/search/mod.rs b/crates/meilisearch/src/search/mod.rs index 1c8fbbe0f..2e8342612 100644 --- a/crates/meilisearch/src/search/mod.rs +++ b/crates/meilisearch/src/search/mod.rs @@ -1901,4 +1901,4 @@ fn parse_filter_array(arr: &[Value]) -> Result, MeilisearchHttpEr } Ok(Filter::from_array(ands)?) -} \ No newline at end of file +}