From 18796d6e6a3a4e3e07627440ccb21c2778787885 Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 20 Feb 2023 13:45:51 +0100 Subject: [PATCH] Consider null as a valid geo object --- meilisearch/tests/documents/add_documents.rs | 47 +++++++++++++++++++ milli/src/update/index_documents/enrich.rs | 1 + .../extract/extract_geo_points.rs | 1 + 3 files changed, 49 insertions(+) diff --git a/meilisearch/tests/documents/add_documents.rs b/meilisearch/tests/documents/add_documents.rs index e553dcacd..e1530ccc0 100644 --- a/meilisearch/tests/documents/add_documents.rs +++ b/meilisearch/tests/documents/add_documents.rs @@ -1027,6 +1027,53 @@ async fn error_document_field_limit_reached() { @""); } +#[actix_rt::test] +async fn add_documents_with_geo_field() { + let server = Server::new().await; + let index = server.index("doggo"); + index.update_settings(json!({"sortableAttributes": ["_geo"]})).await; + + let documents = json!([ + { + "id": "1", + }, + { + "id": "2", + "_geo": null, + }, + { + "id": "3", + "_geo": { "lat": 1, "lng": 1 }, + }, + { + "id": "4", + "_geo": { "lat": "1", "lng": "1" }, + }, + ]); + + index.add_documents(documents, None).await; + let response = index.wait_task(1).await; + snapshot!(json_string!(response, { ".duration" => "[duration]", ".enqueuedAt" => "[date]", ".startedAt" => "[date]", ".finishedAt" => "[date]" }), + @r###" + { + "uid": 1, + "indexUid": "doggo", + "status": "succeeded", + "type": "documentAdditionOrUpdate", + "canceledBy": null, + "details": { + "receivedDocuments": 4, + "indexedDocuments": 4 + }, + "error": null, + "duration": "[duration]", + "enqueuedAt": "[date]", + "startedAt": "[date]", + "finishedAt": "[date]" + } + "###); +} + #[actix_rt::test] async fn add_documents_invalid_geo_field() { let server = Server::new().await; diff --git a/milli/src/update/index_documents/enrich.rs b/milli/src/update/index_documents/enrich.rs index ed04e9962..09599ac82 100644 --- a/milli/src/update/index_documents/enrich.rs +++ b/milli/src/update/index_documents/enrich.rs @@ -395,6 +395,7 @@ pub fn validate_geo_from_json(id: &DocumentId, bytes: &[u8]) -> Result Ok(Err(MissingLongitude { document_id: debug_id() })), (None, None) => Ok(Err(MissingLatitudeAndLongitude { document_id: debug_id() })), }, + Value::Null => Ok(Ok(())), value => Ok(Err(NotAnObject { document_id: debug_id(), value })), } } diff --git a/milli/src/update/index_documents/extract/extract_geo_points.rs b/milli/src/update/index_documents/extract/extract_geo_points.rs index 55044e712..ddb38abe5 100644 --- a/milli/src/update/index_documents/extract/extract_geo_points.rs +++ b/milli/src/update/index_documents/extract/extract_geo_points.rs @@ -59,6 +59,7 @@ pub fn extract_geo_points( } else if lat.is_some() && lng.is_none() { return Err(GeoError::MissingLongitude { document_id: document_id() })?; } + // else => the _geo object was `null`, there is nothing to do } writer_into_reader(writer)