Skip to content

Commit

Permalink
Move duplicates removal when generating results instead of when displ…
Browse files Browse the repository at this point in the history
…aying them
  • Loading branch information
GuillaumeGomez committed Dec 20, 2021
1 parent 60f3bd7 commit 879d28d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit 879d28d

Please sign in to comment.