diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-21 08:33:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-21 08:33:41 +0100 |
| commit | b9c3243801d05a789b1be1e220b81f73f76c8672 (patch) | |
| tree | 8b1682671a3558252c663c5c48b736e938371993 | |
| parent | 4d840a6e45d464621d098cdefbe3900584d0ee9b (diff) | |
| parent | 879d28d3c1743ec474ec269a7cf76ad338868712 (diff) | |
| download | rust-b9c3243801d05a789b1be1e220b81f73f76c8672.tar.gz rust-b9c3243801d05a789b1be1e220b81f73f76c8672.zip | |
Rollup merge of #92127 - GuillaumeGomez:search-results-duplicate-removal, r=jsha
Move duplicates removal when generating results instead of when displaying them Currently, we store 200 results per tab and then display them. However, it was possible to have duplicates which is why we have this check. However, instead of doing it when displaying the results, it's much better instead to do it even before to simplify the display part a bit. r? `@jsha`
| -rw-r--r-- | src/librustdoc/html/static/js/search.js | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index d419e384a59..971bd3930cf 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -152,16 +152,26 @@ window.initSearch = function(rawSearchIndex) { removeEmptyStringsFromArray(split); function transformResults(results) { + var duplicates = {}; var out = []; + for (var i = 0, len = results.length; i < len; ++i) { - if (results[i].id > -1) { - var obj = searchIndex[results[i].id]; - obj.lev = results[i].lev; + var result = results[i]; + + if (result.id > -1) { + var obj = searchIndex[result.id]; + obj.lev = result.lev; var res = buildHrefAndPath(obj); obj.displayPath = pathSplitter(res[0]); obj.fullPath = obj.displayPath + obj.name; // To be sure than it some items aren't considered as duplicate. obj.fullPath += "|" + obj.ty; + + if (duplicates[obj.fullPath]) { + continue; + } + duplicates[obj.fullPath] = true; + obj.href = res[1]; out.push(obj); if (out.length >= MAX_RESULTS) { @@ -971,19 +981,11 @@ window.initSearch = function(rawSearchIndex) { } var output = document.createElement("div"); - var duplicates = {}; var length = 0; if (array.length > 0) { output.className = "search-results " + extraClass; array.forEach(function(item) { - if (item.is_alias !== true) { - if (duplicates[item.fullPath]) { - return; - } - duplicates[item.fullPath] = true; - } - var name = item.name; var type = itemTypes[item.ty]; |
