Show substances in search results

This commit is contained in:
Tiffany Bennett 2016-10-07 19:54:52 -04:00
parent 71af018e18
commit b745a44389
2 changed files with 13 additions and 2 deletions

View file

@ -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,

View file

@ -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()