From 4988199bb915f8e2757c7a197c2769afe25be1ed Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 8 Aug 2023 16:29:25 +0200 Subject: [PATCH] ensure the geoboundingbox works with strings and int geofields in milli and meilisearch --- meilisearch/tests/search/geo.rs | 57 +++++++++++++++++++++++++++++++++ milli/src/index.rs | 8 ++--- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/meilisearch/tests/search/geo.rs b/meilisearch/tests/search/geo.rs index 4253bc210..5eec5857a 100644 --- a/meilisearch/tests/search/geo.rs +++ b/meilisearch/tests/search/geo.rs @@ -1,3 +1,4 @@ +use meili_snap::{json_string, snapshot}; use once_cell::sync::Lazy; use serde_json::{json, Value}; @@ -60,3 +61,59 @@ async fn geo_sort_with_geo_strings() { ) .await; } + +#[actix_rt::test] +async fn geo_bounding_box_with_string_and_number() { + let server = Server::new().await; + let index = server.index("test"); + + let documents = DOCUMENTS.clone(); + index.update_settings_filterable_attributes(json!(["_geo"])).await; + index.update_settings_sortable_attributes(json!(["_geo"])).await; + index.add_documents(documents, None).await; + index.wait_task(2).await; + + index + .search( + json!({ + "filter": "_geoBoundingBox([89, 179], [-89, -179])", + }), + |response, code| { + assert_eq!(code, 200, "{}", response); + snapshot!(json_string!(response, { ".processingTimeMs" => "[time]" }), @r###" + { + "hits": [ + { + "id": 1, + "name": "Taco Truck", + "address": "444 Salsa Street, Burritoville", + "type": "Mexican", + "rating": 9, + "_geo": { + "lat": 34.0522, + "lng": -118.2437 + } + }, + { + "id": 2, + "name": "La Bella Italia", + "address": "456 Elm Street, Townsville", + "type": "Italian", + "rating": 9, + "_geo": { + "lat": "45.4777599", + "lng": "9.1967508" + } + } + ], + "query": "", + "processingTimeMs": "[time]", + "limit": 20, + "offset": 0, + "estimatedTotalHits": 2 + } + "###); + }, + ) + .await; +} diff --git a/milli/src/index.rs b/milli/src/index.rs index 0ddfcda94..23c0f5fae 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -1718,11 +1718,11 @@ pub(crate) mod tests { .unwrap(); index .add_documents(documents!([ - { "id": 0, "_geo": { "lat": 0, "lng": 0 } }, - { "id": 1, "_geo": { "lat": 0, "lng": -175 } }, - { "id": 2, "_geo": { "lat": 0, "lng": 175 } }, + { "id": 0, "_geo": { "lat": "0", "lng": "0" } }, + { "id": 1, "_geo": { "lat": 0, "lng": "-175" } }, + { "id": 2, "_geo": { "lat": "0", "lng": 175 } }, { "id": 3, "_geo": { "lat": 85, "lng": 0 } }, - { "id": 4, "_geo": { "lat": -85, "lng": 0 } }, + { "id": 4, "_geo": { "lat": "-85", "lng": "0" } }, ])) .unwrap();