Make matches work with numerical value

This commit is contained in:
Thearas 2021-11-10 23:10:30 +08:00
parent 15cb4dafa9
commit ac5535055f

View File

@ -310,6 +310,9 @@ fn compute_value_matches<'a, A: AsRef<[u8]>>(
Value::Object(vals) => vals Value::Object(vals) => vals
.values() .values()
.for_each(|val| compute_value_matches(infos, val, matcher, analyzer)), .for_each(|val| compute_value_matches(infos, val, matcher, analyzer)),
Value::Number(number) => {
compute_value_matches(infos, &Value::String(number.to_string()), matcher, analyzer)
}
_ => (), _ => (),
} }
} }
@ -1424,13 +1427,15 @@ mod test {
"color": "Green", "color": "Green",
"name": "Lucas Hess", "name": "Lucas Hess",
"gender": "male", "gender": "male",
"price": 3.5,
"address": "412 Losee Terrace, Blairstown, Georgia, 2825", "address": "412 Losee Terrace, Blairstown, Georgia, 2825",
"about": "Mollit ad in exercitation quis Laboris . Anim est ut consequat fugiat duis magna aliquip velit nisi. Commodo eiusmod est consequat proident consectetur aliqua enim fugiat. Aliqua adipisicing laboris elit proident enim veniam laboris mollit. Incididunt fugiat minim ad nostrud deserunt tempor in. Id irure officia labore qui est labore nulla nisi. Magna sit quis tempor esse consectetur amet labore duis aliqua consequat.\r\n" "about": "Mollit ad in exercitation quis Laboris . Anim est ut consequat fugiat duis magna aliquip velit nisi. Commodo eiusmod est consequat proident consectetur aliqua enim fugiat. Aliqua adipisicing laboris elit proident enim veniam laboris mollit. Incididunt fugiat minim ad nostrud deserunt tempor in. Id irure officia labore qui est labore nulla nisi. Magna sit quis tempor esse consectetur amet labore duis aliqua consequat.\r\n"
}"#).unwrap(); }"#).unwrap();
let mut matcher = BTreeMap::new(); let mut matcher = BTreeMap::new();
matcher.insert("green", Some(3)); matcher.insert("green", Some(5));
matcher.insert("mollit", Some(6)); matcher.insert("mollit", Some(6));
matcher.insert("laboris", Some(7)); matcher.insert("laboris", Some(7));
matcher.insert("3", Some(1));
let stop_words = fst::Set::default(); let stop_words = fst::Set::default();
let mut config = AnalyzerConfig::default(); let mut config = AnalyzerConfig::default();
@ -1440,7 +1445,7 @@ mod test {
let matches = compute_matches(&matcher, &value, &analyzer); let matches = compute_matches(&matcher, &value, &analyzer);
assert_eq!( assert_eq!(
format!("{:?}", matches), format!("{:?}", matches),
r##"{"about": [MatchInfo { start: 0, length: 6 }, MatchInfo { start: 31, length: 7 }, MatchInfo { start: 191, length: 7 }, MatchInfo { start: 225, length: 7 }, MatchInfo { start: 233, length: 6 }], "color": [MatchInfo { start: 0, length: 3 }]}"## r##"{"about": [MatchInfo { start: 0, length: 6 }, MatchInfo { start: 31, length: 7 }, MatchInfo { start: 191, length: 7 }, MatchInfo { start: 225, length: 7 }, MatchInfo { start: 233, length: 6 }], "color": [MatchInfo { start: 0, length: 5 }], "price": [MatchInfo { start: 0, length: 1 }]}"##
); );
} }