Also match patch in Index::find

Previously, we only compared the type names when searching for matches
in the search index.  With this patch, we also check the path:  If the
full name of the item ends with the keyword (prepended with :: to avoid
partial matches), we return a match.
This commit is contained in:
Robin Krahl 2020-07-19 22:44:21 +02:00
parent 61fdf31c0a
commit bd71f41458
No known key found for this signature in database
GPG Key ID: 8E9B0870524F69D8

View File

@ -106,17 +106,20 @@ impl Index {
}
pub fn find(&self, keyword: &str) -> Vec<IndexItem> {
let keyword = format!("::{}", keyword);
let mut matches: Vec<IndexItem> = Vec::new();
for (krate, data) in &self.data.crates {
for item in &data.items {
if item.name == keyword {
let path = if item.path.is_empty() {
krate
} else {
&item.path
};
let full_name = format!("{}::{}", path, &item.name);
if full_name.ends_with(&keyword) {
matches.push(IndexItem {
name: item.name.clone(),
path: if item.path.is_empty() {
krate.to_owned()
} else {
item.path.clone()
},
path: path.to_owned(),
description: item.desc.clone(),
});
}