mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-26 23:06:27 +00:00
Add geo bounding box filter
This commit is contained in:
@ -522,6 +522,26 @@ pub async fn shared_index_with_geo_documents() -> &'static Index<'static, Shared
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn shared_index_geojson_documents() -> &'static Index<'static, Shared> {
|
||||
static INDEX: OnceCell<Index<'static, Shared>> = OnceCell::const_new();
|
||||
INDEX
|
||||
.get_or_init(|| async {
|
||||
// Retrieved from https://gitlab-forge.din.developpement-durable.gouv.fr/pub/geomatique/descartes/d-map/-/blob/main/demo/examples/commons/countries.geojson?ref_type=heads
|
||||
let server = Server::new_shared();
|
||||
let index = server._index("SHARED_GEOJSON_DOCUMENTS").to_shared();
|
||||
let countries = include_str!("../documents/geojson/assets/countries.geojson");
|
||||
let lille = serde_json::from_str::<serde_json::Value>(countries).unwrap();
|
||||
let (response, _code) = index._add_documents(Value(lille), Some("name")).await;
|
||||
server.wait_task(response.uid()).await.succeeded();
|
||||
|
||||
let (response, _code) =
|
||||
index._update_settings(json!({"filterableAttributes": ["_geojson"]})).await;
|
||||
server.wait_task(response.uid()).await.succeeded();
|
||||
index
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn shared_index_for_fragments() -> Index<'static, Shared> {
|
||||
static INDEX: OnceCell<(Server<Shared>, String)> = OnceCell::const_new();
|
||||
let (server, uid) = INDEX
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,7 @@
|
||||
use crate::{common::Server, json};
|
||||
use crate::{
|
||||
common::{shared_index_geojson_documents, Server},
|
||||
json,
|
||||
};
|
||||
use meili_snap::{json_string, snapshot};
|
||||
|
||||
const LILLE: &str = include_str!("assets/lille.geojson");
|
||||
@ -281,3 +284,99 @@ async fn partial_update_geojson() {
|
||||
index.search_get("?filter=_geoPolygon([0.9,0.9],[2,0.9],[2,2],[0.9,2])").await;
|
||||
assert_eq!(response.get("hits").unwrap().as_array().unwrap().len(), 0);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn geo_bounding_box() {
|
||||
let index = shared_index_geojson_documents().await;
|
||||
|
||||
// The bounding box is a polygon over middle Europe
|
||||
let (response, code) =
|
||||
index.search_get("?filter=_geoBoundingBox([21.43443989912143,50.53987503447863],[0.54979129195425,43.76393151539099])&attributesToRetrieve=name").await;
|
||||
snapshot!(code, @"200 OK");
|
||||
snapshot!(response, @r#"
|
||||
{
|
||||
"hits": [
|
||||
{
|
||||
"name": "Austria"
|
||||
},
|
||||
{
|
||||
"name": "Belgium"
|
||||
},
|
||||
{
|
||||
"name": "Bosnia_and_Herzegovina"
|
||||
},
|
||||
{
|
||||
"name": "Switzerland"
|
||||
},
|
||||
{
|
||||
"name": "Czech_Republic"
|
||||
},
|
||||
{
|
||||
"name": "Germany"
|
||||
},
|
||||
{
|
||||
"name": "France"
|
||||
},
|
||||
{
|
||||
"name": "Croatia"
|
||||
},
|
||||
{
|
||||
"name": "Hungary"
|
||||
},
|
||||
{
|
||||
"name": "Italy"
|
||||
},
|
||||
{
|
||||
"name": "Luxembourg"
|
||||
},
|
||||
{
|
||||
"name": "Netherlands"
|
||||
},
|
||||
{
|
||||
"name": "Poland"
|
||||
},
|
||||
{
|
||||
"name": "Romania"
|
||||
},
|
||||
{
|
||||
"name": "Republic_of_Serbia"
|
||||
},
|
||||
{
|
||||
"name": "Slovakia"
|
||||
},
|
||||
{
|
||||
"name": "Slovenia"
|
||||
}
|
||||
],
|
||||
"query": "",
|
||||
"processingTimeMs": "[duration]",
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"estimatedTotalHits": 17
|
||||
}
|
||||
"#);
|
||||
|
||||
// Between Russia and Alaska
|
||||
// WARNING: This test doesn't pass, the countries are those I imagine being found but maybe there is also Canada or something
|
||||
let (response, code) = index
|
||||
.search_get("?filter=_geoBoundingBox([70,-148],[63,152])&attributesToRetrieve=name")
|
||||
.await;
|
||||
snapshot!(code, @"200 OK");
|
||||
snapshot!(response, @r#"
|
||||
{
|
||||
"hits": [
|
||||
{
|
||||
"name": "Russia"
|
||||
},
|
||||
{
|
||||
"name": "United_States_of_America"
|
||||
}
|
||||
],
|
||||
"query": "",
|
||||
"processingTimeMs": "[duration]",
|
||||
"limit": 20,
|
||||
"offset": 0,
|
||||
"estimatedTotalHits": 2
|
||||
}
|
||||
"#);
|
||||
}
|
||||
|
Reference in New Issue
Block a user