Skip to content

Commit cf9209f

Browse files
Improve results
1 parent e6db79f commit cf9209f

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

src/librustdoc/html/static/main.js

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,16 @@
454454
var obj = searchIndex[results[i].id];
455455
obj.lev = results[i].lev;
456456
if (isType !== true || obj.type) {
457+
var res = buildHrefAndPath(obj);
458+
obj.displayPath = pathSplitter(res[0]);
459+
obj.fullPath = obj.displayPath + obj.name;
460+
obj.href = res[1];
457461
out.push(obj);
462+
if (out.length >= MAX_RESULTS) {
463+
break;
464+
}
458465
}
459466
}
460-
if (out.length >= MAX_RESULTS) {
461-
break;
462-
}
463467
}
464468
return out;
465469
}
@@ -1017,6 +1021,12 @@
10171021
ALIASES[window.currentCrate][query.raw]) {
10181022
var aliases = ALIASES[window.currentCrate][query.raw];
10191023
for (var i = 0; i < aliases.length; ++i) {
1024+
aliases[i].is_alias = true;
1025+
aliases[i].alias = query.raw;
1026+
var res = buildHrefAndPath(aliases[i]);
1027+
aliases[i].displayPath = pathSplitter(res[0]);
1028+
aliases[i].fullPath = aliases[i].displayPath + aliases[i].name;
1029+
aliases[i].href = res[1];
10201030
ret['others'].unshift(aliases[i]);
10211031
if (ret['others'].length > MAX_RESULTS) {
10221032
ret['others'].pop();
@@ -1179,16 +1189,6 @@
11791189
};
11801190
}
11811191

1182-
function escape(content) {
1183-
var h1 = document.createElement('h1');
1184-
h1.textContent = content;
1185-
return h1.innerHTML;
1186-
}
1187-
1188-
function pathSplitter(path) {
1189-
return '<span>' + path.replace(/::/g, '::</span><span>');
1190-
}
1191-
11921192
function buildHrefAndPath(item) {
11931193
var displayPath;
11941194
var href;
@@ -1227,19 +1227,30 @@
12271227
return [displayPath, href];
12281228
}
12291229

1230+
function escape(content) {
1231+
var h1 = document.createElement('h1');
1232+
h1.textContent = content;
1233+
return h1.innerHTML;
1234+
}
1235+
1236+
function pathSplitter(path) {
1237+
return '<span>' + path.replace(/::/g, '::</span><span>');
1238+
}
1239+
12301240
function addTab(array, query, display) {
12311241
var extraStyle = '';
12321242
if (display === false) {
12331243
extraStyle = ' style="display: none;"';
12341244
}
12351245

12361246
var output = '';
1247+
var duplicates = {};
12371248
if (array.length > 0) {
12381249
output = '<table class="search-results"' + extraStyle + '>';
12391250
var shown = [];
12401251

12411252
array.forEach(function(item) {
1242-
var name, type, href, displayPath;
1253+
var name, type;
12431254

12441255
var id_ty = item.ty + item.path + item.name;
12451256
if (shown.indexOf(id_ty) !== -1) {
@@ -1250,15 +1261,23 @@
12501261
name = item.name;
12511262
type = itemTypes[item.ty];
12521263

1253-
var res = buildHrefAndPath(item);
1254-
var href = res[1];
1255-
var displayPath = res[0];
1264+
if (item.is_alias !== true) {
1265+
var fullPath = item.displayPath + name;
1266+
1267+
if (duplicates[fullPath]) {
1268+
return;
1269+
}
1270+
duplicates[fullPath] = true;
1271+
}
12561272

12571273
output += '<tr class="' + type + ' result"><td>' +
1258-
'<a href="' + href + '">' +
1259-
pathSplitter(displayPath) + '<span class="' + type + '">' +
1274+
'<a href="' + item.href + '">' +
1275+
(item.is_alias === true ?
1276+
('<span><b>' + item.alias + ' </b></span><span ' +
1277+
'class="grey"><i>&nbsp;- see&nbsp;</i></span>') : '') +
1278+
item.displayPath + '<span class="' + type + '">' +
12601279
name + '</span></a></td><td>' +
1261-
'<a href="' + href + '">' +
1280+
'<a href="' + item.href + '">' +
12621281
'<span class="desc">' + escape(item.desc) +
12631282
'&nbsp;</span></a></td></tr>';
12641283
});
@@ -1284,8 +1303,7 @@
12841303
if (results['others'].length === 1 &&
12851304
getCurrentValue('rustdoc-go-to-only-result') === "true") {
12861305
var elem = document.createElement('a');
1287-
var res = buildHrefAndPath(results['others'][0]);
1288-
elem.href = res[1];
1306+
elem.href = results['others'][0].href;
12891307
elem.style.display = 'none';
12901308
// For firefox, we need the element to be in the DOM so it can be clicked.
12911309
document.body.appendChild(elem);
@@ -1347,12 +1365,13 @@
13471365
}
13481366
}
13491367
if (queries.length > 1) {
1350-
function getSmallest(arrays, positions) {
1368+
function getSmallest(arrays, positions, notDuplicates) {
13511369
var start = null;
13521370

13531371
for (var it = 0; it < positions.length; ++it) {
13541372
if (arrays[it].length > positions[it] &&
1355-
(start === null || start > arrays[it][positions[it]].lev)) {
1373+
(start === null || start > arrays[it][positions[it]].lev) &&
1374+
!notDuplicates[arrays[it][positions[it]].fullPath]) {
13561375
start = arrays[it][positions[it]].lev;
13571376
}
13581377
}
@@ -1362,19 +1381,23 @@
13621381
function mergeArrays(arrays) {
13631382
var ret = [];
13641383
var positions = [];
1384+
var notDuplicates = {};
13651385

13661386
for (var x = 0; x < arrays.length; ++x) {
13671387
positions.push(0);
13681388
}
13691389
while (ret.length < MAX_RESULTS) {
1370-
var smallest = getSmallest(arrays, positions);
1390+
var smallest = getSmallest(arrays, positions, notDuplicates);
1391+
13711392
if (smallest === null) {
13721393
break;
13731394
}
13741395
for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
13751396
if (arrays[x].length > positions[x] &&
1376-
arrays[x][positions[x]].lev === smallest) {
1397+
arrays[x][positions[x]].lev === smallest &&
1398+
!notDuplicates[arrays[x][positions[x]].fullPath]) {
13771399
ret.push(arrays[x][positions[x]]);
1400+
notDuplicates[arrays[x][positions[x]].fullPath] = true;
13781401
positions[x] += 1;
13791402
}
13801403
}

src/librustdoc/html/static/rustdoc.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,4 +1326,8 @@ kbd {
13261326
}
13271327
#all-types > p {
13281328
margin: 5px 0;
1329+
}
1330+
1331+
.search-results td span.grey {
1332+
color: #ccc;
13291333
}

0 commit comments

Comments
 (0)