From 2d7a1bfce049a8d37cbab3ce23f914c1d979c97b Mon Sep 17 00:00:00 2001 From: qdequele Date: Tue, 4 Feb 2020 18:09:19 +0100 Subject: [PATCH] fix un-rankable fields errors; fix #463 --- meilisearch-core/src/number.rs | 12 +++++++++++- meilisearch-core/src/serde/serializer.rs | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/meilisearch-core/src/number.rs b/meilisearch-core/src/number.rs index 7817be3e5..a9b2e606d 100644 --- a/meilisearch-core/src/number.rs +++ b/meilisearch-core/src/number.rs @@ -11,6 +11,13 @@ pub enum Number { Unsigned(u64), Signed(i64), Float(OrderedFloat), + Null, +} + +impl Default for Number { + fn default() -> Self { + Self::Null + } } impl FromStr for Number { @@ -56,7 +63,7 @@ impl PartialOrd for Number { impl Ord for Number { fn cmp(&self, other: &Self) -> Ordering { - use Number::{Float, Signed, Unsigned}; + use Number::{Float, Signed, Unsigned, Null}; match (*self, *other) { (Unsigned(a), Unsigned(b)) => a.cmp(&b), @@ -80,6 +87,9 @@ impl Ord for Number { (Float(a), Unsigned(b)) => a.cmp(&OrderedFloat(b as f64)), (Float(a), Signed(b)) => a.cmp(&OrderedFloat(b as f64)), (Float(a), Float(b)) => a.cmp(&b), + (Null, Null) => Ordering::Equal, + (_, Null) => Ordering::Less, + (Null, _) => Ordering::Greater, } } } diff --git a/meilisearch-core/src/serde/serializer.rs b/meilisearch-core/src/serde/serializer.rs index 20e26886d..6142e96e7 100644 --- a/meilisearch-core/src/serde/serializer.rs +++ b/meilisearch-core/src/serde/serializer.rs @@ -353,7 +353,7 @@ where } if schema.is_ranked(field_id) { - let number = value.serialize(ConvertToNumber)?; + let number = value.serialize(ConvertToNumber).unwrap_or_default(); ranked_map.insert(document_id, field_id, number); }