Search crate from crate index

This commit is contained in:
Folyd 2019-11-19 17:26:04 +08:00
parent e945c3cd29
commit d352ce4372
3 changed files with 12 additions and 1 deletions

View file

@ -109,3 +109,5 @@ CrateSearch.prototype.search = function(keyword, limit = 5) {
return this.crateIndex[item.id];
});
};
const crateSearcher = new CrateSearch(crateIndex);

View file

@ -25,6 +25,8 @@
"settings.js",
"search.js",
"search-index.js",
"crates-index.js",
"crate-search.js",
"omnibox.js",
"main.js"
]

View file

@ -71,6 +71,13 @@ Omnibox.prototype.appendErrorIndexResult = function(query, length) {
};
Omnibox.prototype.appendCratesResult = function(query) {
let crates = crateSearcher.search(query);
for (let crate of crates) {
this.suggestResults.push({
content: `https://crates.io/crates/${crate.id}`,
description: `[crate] ${this.tagged("match", crate.id)} v${crate.version} - ${this.tagged("dim", this.escape(crate.description))}`,
});
}
this.suggestResults.push({
content: "https://crates.io/search?q=" + encodeURIComponent(query),
description: "Search Rust crates for " + this.tagged("match", query) + " on https://crates.io"