|
|
@ -10,17 +10,27 @@ pub async fn search(query: &str) -> XKCDResult<Vec<(String, u32)>> {
|
|
|
|
.into_iter()
|
|
|
|
.into_iter()
|
|
|
|
.map(|s| s.to_lowercase())
|
|
|
|
.map(|s| s.to_lowercase())
|
|
|
|
.collect();
|
|
|
|
.collect();
|
|
|
|
let entries = archive
|
|
|
|
let mut entries: Vec<(usize, String, u32)> = archive
|
|
|
|
.into_iter()
|
|
|
|
.into_iter()
|
|
|
|
.filter(|(key, _)| {
|
|
|
|
.filter_map(|(key, id)| {
|
|
|
|
words
|
|
|
|
let score = words
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.find(|w| key.to_lowercase().contains(*w))
|
|
|
|
.filter(|w| key.to_lowercase().contains(*w))
|
|
|
|
.is_some()
|
|
|
|
.count();
|
|
|
|
|
|
|
|
if score <= 0 {
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Some((score, key, id))
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
entries.sort_by_key(|(s, _, _)| *s);
|
|
|
|
|
|
|
|
entries.reverse();
|
|
|
|
|
|
|
|
|
|
|
|
Ok(entries)
|
|
|
|
Ok(entries
|
|
|
|
|
|
|
|
.into_iter()
|
|
|
|
|
|
|
|
.map(|(_, title, id)| (title, id))
|
|
|
|
|
|
|
|
.collect())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Searches for a comic with a fuzzy compare function that assigns a score
|
|
|
|
/// Searches for a comic with a fuzzy compare function that assigns a score
|
|
|
|