From 47ee93b0bd7e81ee042aa5f891a01c00c88f9454 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 22 Sep 2021 16:29:11 +0200 Subject: [PATCH] return an error when _geoPoint is used but _geo is not sortable --- milli/src/search/mod.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index 3984ed130..bec059d46 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -20,7 +20,7 @@ pub use self::matching_words::MatchingWords; use self::query_tree::QueryTreeBuilder; use crate::error::UserError; use crate::search::criteria::r#final::{Final, FinalResult}; -use crate::{AscDesc, Criterion, DocumentId, Index, Result}; +use crate::{AscDesc, Criterion, DocumentId, Index, Member, Result}; // Building these factories is not free. static LEVDIST0: Lazy = Lazy::new(|| LevBuilder::new(0, true)); @@ -147,15 +147,20 @@ impl<'a> Search<'a> { if let Some(sort_criteria) = &self.sort_criteria { let sortable_fields = self.index.sortable_fields(self.rtxn)?; for asc_desc in sort_criteria { - // we are not supposed to find any geoPoint in the criterion - if let Some(field) = asc_desc.field() { - if !sortable_fields.contains(field) { + match asc_desc.member() { + Member::Field(ref field) if !sortable_fields.contains(field) => { return Err(UserError::InvalidSortableAttribute { field: field.to_string(), valid_fields: sortable_fields, - } - .into()); + })? } + Member::Geo(_) if !sortable_fields.contains("_geo") => { + return Err(UserError::InvalidSortableAttribute { + field: "_geo".to_string(), + valid_fields: sortable_fields, + })? + } + _ => (), } } }