From a2cd7214f0fc31cd983a46fa19d2f9fed5ca3d32 Mon Sep 17 00:00:00 2001 From: Philipp Ahlner Date: Wed, 18 Jan 2023 13:24:46 +0100 Subject: [PATCH] Fixes error message when lat/lng are unparseable --- milli/src/index.rs | 4 +--- milli/src/update/index_documents/enrich.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/milli/src/index.rs b/milli/src/index.rs index 7ed9af424..0ab596fa9 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -2321,9 +2321,7 @@ pub(crate) mod tests { .unwrap_err(); assert!(matches!( err1, - Error::UserError(UserError::InvalidGeoField( - GeoError::BadLatitudeAndLongitude { .. } - )) + Error::UserError(UserError::InvalidGeoField(GeoError::BadLatitudeAndLongitude { .. })) )); db_snap!(index, geo_faceted_documents_ids); // ensure that no more document was inserted diff --git a/milli/src/update/index_documents/enrich.rs b/milli/src/update/index_documents/enrich.rs index 3331497c9..4c735856d 100644 --- a/milli/src/update/index_documents/enrich.rs +++ b/milli/src/update/index_documents/enrich.rs @@ -98,7 +98,12 @@ pub fn enrich_documents_batch( // If the settings specifies that a _geo field must be used therefore we must check the // validity of it in all the documents of this batch and this is when we return `Some`. let geo_field_id = match documents_batch_index.id("_geo") { - Some(geo_field_id) if index.sortable_fields(rtxn)?.contains("_geo") => Some(geo_field_id), + Some(geo_field_id) + if index.sortable_fields(rtxn)?.contains("_geo") + || index.filterable_fields(rtxn)?.contains("_geo") => + { + Some(geo_field_id) + } _otherwise => None, }; @@ -367,7 +372,9 @@ pub fn extract_finite_float_from_value(value: Value) -> StdResult { pub fn validate_geo_from_json(id: &DocumentId, bytes: &[u8]) -> Result> { use GeoError::*; - let debug_id = || Value::from(id.debug()); + let debug_id = || { + serde_json::from_slice(id.value().as_bytes()).unwrap_or_else(|_| Value::from(id.debug())) + }; match serde_json::from_slice(bytes).map_err(InternalError::SerdeJson)? { Value::Object(mut object) => match (object.remove("lat"), object.remove("lng")) { (Some(lat), Some(lng)) => {