1893: Make matches work with numerical value r=MarinPostma a=Thearas

# Pull Request

## What does this PR do?

Implement #1883.

I have test this PR with unit test. It appears to be working properly:
![image](https://user-images.githubusercontent.com/44015907/141141082-dad8cd18-e803-408f-ad6a-c7a212b7ec88.png)

PTAL `@curquiza` 

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?


Co-authored-by: Thearas <thearas850@gmail.com>
This commit is contained in:
bors[bot] 2021-11-29 13:38:57 +00:00 committed by GitHub
commit c9f3726447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -310,6 +310,9 @@ fn compute_value_matches<'a, A: AsRef<[u8]>>(
Value::Object(vals) => vals
.values()
.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",
"name": "Lucas Hess",
"gender": "male",
"price": 3.5,
"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"
}"#).unwrap();
let mut matcher = BTreeMap::new();
matcher.insert("green", Some(3));
matcher.insert("green", Some(5));
matcher.insert("mollit", Some(6));
matcher.insert("laboris", Some(7));
matcher.insert("3", Some(1));
let stop_words = fst::Set::default();
let mut config = AnalyzerConfig::default();
@ -1440,7 +1445,7 @@ mod test {
let matches = compute_matches(&matcher, &value, &analyzer);
assert_eq!(
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 }]}"##
);
}