mirror of
https://github.com/tiffany352/rink-rs
synced 2024-11-10 13:44:15 +00:00
Show substances in search results
This commit is contained in:
parent
71af018e18
commit
b745a44389
2 changed files with 13 additions and 2 deletions
12
src/eval.rs
12
src/eval.rs
|
@ -746,8 +746,16 @@ impl Context {
|
|||
.into_iter()
|
||||
.map(|x| {
|
||||
let parts = self.lookup(x)
|
||||
.expect("Search returned non-existent result")
|
||||
.to_parts(self);
|
||||
.map(|x| x.to_parts(self))
|
||||
.or_else(|| if self.substances.get(x).is_some() {
|
||||
Some(NumberParts {
|
||||
quantity: Some("substance".to_owned()),
|
||||
.. Default::default()
|
||||
})
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.expect("Search returned non-existent result");
|
||||
NumberParts {
|
||||
unit: Some(x.to_owned()),
|
||||
quantity: parts.quantity,
|
||||
|
|
|
@ -65,6 +65,9 @@ pub fn search<'a>(ctx: &'a Context, query: &str, num_results: usize) -> Vec<&'a
|
|||
for (_u, k) in &ctx.quantities {
|
||||
try(&**k);
|
||||
}
|
||||
for (k, _sub) in &ctx.substances {
|
||||
try(&**k);
|
||||
}
|
||||
}
|
||||
results.into_sorted_vec()
|
||||
.into_iter()
|
||||
|
|
Loading…
Reference in a new issue