Rollup merge of #64094 - kawa-yoiko:rustdoc-search, r=GuillaumeGomez
Improve searching in rustdoc and add tests 👋 I have made searching in rustdoc more intuitive, added a couple more tests and made a little shell script to aid testing. Closes #63005. It took me quite a while to figure out how to run the tests for rustdoc (instead of running tests for other crates with rustdoc); the only pointer I found was [hidden in the rustc book](https://rust-lang.github.io/rustc-guide/rustdoc.html#cheat-sheet). Maybe this could be better documented? I shall be delighted to help if it is desirable.
This commit is contained in:
commit
ab75a1713a
8 changed files with 169 additions and 10 deletions
|
@ -547,6 +547,11 @@ if (!DOMTokenList.prototype.remove) {
|
|||
results.sort(function(aaa, bbb) {
|
||||
var a, b;
|
||||
|
||||
// sort by exact match with regard to the last word (mismatch goes later)
|
||||
a = (aaa.word !== val);
|
||||
b = (bbb.word !== val);
|
||||
if (a !== b) { return a - b; }
|
||||
|
||||
// Sort by non levenshtein results and then levenshtein results by the distance
|
||||
// (less changes required to match means higher rankings)
|
||||
a = (aaa.lev);
|
||||
|
@ -558,11 +563,6 @@ if (!DOMTokenList.prototype.remove) {
|
|||
b = (bbb.item.crate !== window.currentCrate);
|
||||
if (a !== b) { return a - b; }
|
||||
|
||||
// sort by exact match (mismatch goes later)
|
||||
a = (aaa.word !== valLower);
|
||||
b = (bbb.word !== valLower);
|
||||
if (a !== b) { return a - b; }
|
||||
|
||||
// sort by item name length (longer goes later)
|
||||
a = aaa.word.length;
|
||||
b = bbb.word.length;
|
||||
|
@ -1028,7 +1028,7 @@ if (!DOMTokenList.prototype.remove) {
|
|||
if (lev > MAX_LEV_DISTANCE) {
|
||||
continue;
|
||||
} else if (lev > 0) {
|
||||
lev_add = 1;
|
||||
lev_add = lev / 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1099,10 +1099,6 @@ if (!DOMTokenList.prototype.remove) {
|
|||
if (index !== -1 || lev <= MAX_LEV_DISTANCE) {
|
||||
if (index !== -1 && paths.length < 2) {
|
||||
lev = 0;
|
||||
} else if (searchWords[j] === val) {
|
||||
// Small trick to fix when you're looking for a one letter type
|
||||
// and there are other short named types.
|
||||
lev = -1;
|
||||
}
|
||||
if (results[fullId] === undefined) {
|
||||
results[fullId] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue