fix un-rankable fields errors; fix #463

This commit is contained in:
qdequele 2020-02-04 18:09:19 +01:00
parent 3845b89a16
commit 2d7a1bfce0
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
2 changed files with 12 additions and 2 deletions

View File

@ -11,6 +11,13 @@ pub enum Number {
Unsigned(u64), Unsigned(u64),
Signed(i64), Signed(i64),
Float(OrderedFloat<f64>), Float(OrderedFloat<f64>),
Null,
}
impl Default for Number {
fn default() -> Self {
Self::Null
}
} }
impl FromStr for Number { impl FromStr for Number {
@ -56,7 +63,7 @@ impl PartialOrd for Number {
impl Ord for Number { impl Ord for Number {
fn cmp(&self, other: &Self) -> Ordering { fn cmp(&self, other: &Self) -> Ordering {
use Number::{Float, Signed, Unsigned}; use Number::{Float, Signed, Unsigned, Null};
match (*self, *other) { match (*self, *other) {
(Unsigned(a), Unsigned(b)) => a.cmp(&b), (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), Unsigned(b)) => a.cmp(&OrderedFloat(b as f64)),
(Float(a), Signed(b)) => a.cmp(&OrderedFloat(b as f64)), (Float(a), Signed(b)) => a.cmp(&OrderedFloat(b as f64)),
(Float(a), Float(b)) => a.cmp(&b), (Float(a), Float(b)) => a.cmp(&b),
(Null, Null) => Ordering::Equal,
(_, Null) => Ordering::Less,
(Null, _) => Ordering::Greater,
} }
} }
} }

View File

@ -353,7 +353,7 @@ where
} }
if schema.is_ranked(field_id) { 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); ranked_map.insert(document_id, field_id, number);
} }