|
454 | 454 | var obj = searchIndex[results[i].id];
|
455 | 455 | obj.lev = results[i].lev;
|
456 | 456 | 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]; |
457 | 461 | out.push(obj);
|
| 462 | + if (out.length >= MAX_RESULTS) { |
| 463 | + break; |
| 464 | + } |
458 | 465 | }
|
459 | 466 | }
|
460 |
| - if (out.length >= MAX_RESULTS) { |
461 |
| - break; |
462 |
| - } |
463 | 467 | }
|
464 | 468 | return out;
|
465 | 469 | }
|
|
1017 | 1021 | ALIASES[window.currentCrate][query.raw]) {
|
1018 | 1022 | var aliases = ALIASES[window.currentCrate][query.raw];
|
1019 | 1023 | 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]; |
1020 | 1030 | ret['others'].unshift(aliases[i]);
|
1021 | 1031 | if (ret['others'].length > MAX_RESULTS) {
|
1022 | 1032 | ret['others'].pop();
|
|
1179 | 1189 | };
|
1180 | 1190 | }
|
1181 | 1191 |
|
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 |
| - |
1192 | 1192 | function buildHrefAndPath(item) {
|
1193 | 1193 | var displayPath;
|
1194 | 1194 | var href;
|
|
1227 | 1227 | return [displayPath, href];
|
1228 | 1228 | }
|
1229 | 1229 |
|
| 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 | + |
1230 | 1240 | function addTab(array, query, display) {
|
1231 | 1241 | var extraStyle = '';
|
1232 | 1242 | if (display === false) {
|
1233 | 1243 | extraStyle = ' style="display: none;"';
|
1234 | 1244 | }
|
1235 | 1245 |
|
1236 | 1246 | var output = '';
|
| 1247 | + var duplicates = {}; |
1237 | 1248 | if (array.length > 0) {
|
1238 | 1249 | output = '<table class="search-results"' + extraStyle + '>';
|
1239 | 1250 | var shown = [];
|
1240 | 1251 |
|
1241 | 1252 | array.forEach(function(item) {
|
1242 |
| - var name, type, href, displayPath; |
| 1253 | + var name, type; |
1243 | 1254 |
|
1244 | 1255 | var id_ty = item.ty + item.path + item.name;
|
1245 | 1256 | if (shown.indexOf(id_ty) !== -1) {
|
|
1250 | 1261 | name = item.name;
|
1251 | 1262 | type = itemTypes[item.ty];
|
1252 | 1263 |
|
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 | + } |
1256 | 1272 |
|
1257 | 1273 | 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> - see </i></span>') : '') + |
| 1278 | + item.displayPath + '<span class="' + type + '">' + |
1260 | 1279 | name + '</span></a></td><td>' +
|
1261 |
| - '<a href="' + href + '">' + |
| 1280 | + '<a href="' + item.href + '">' + |
1262 | 1281 | '<span class="desc">' + escape(item.desc) +
|
1263 | 1282 | ' </span></a></td></tr>';
|
1264 | 1283 | });
|
|
1284 | 1303 | if (results['others'].length === 1 &&
|
1285 | 1304 | getCurrentValue('rustdoc-go-to-only-result') === "true") {
|
1286 | 1305 | var elem = document.createElement('a');
|
1287 |
| - var res = buildHrefAndPath(results['others'][0]); |
1288 |
| - elem.href = res[1]; |
| 1306 | + elem.href = results['others'][0].href; |
1289 | 1307 | elem.style.display = 'none';
|
1290 | 1308 | // For firefox, we need the element to be in the DOM so it can be clicked.
|
1291 | 1309 | document.body.appendChild(elem);
|
|
1347 | 1365 | }
|
1348 | 1366 | }
|
1349 | 1367 | if (queries.length > 1) {
|
1350 |
| - function getSmallest(arrays, positions) { |
| 1368 | + function getSmallest(arrays, positions, notDuplicates) { |
1351 | 1369 | var start = null;
|
1352 | 1370 |
|
1353 | 1371 | for (var it = 0; it < positions.length; ++it) {
|
1354 | 1372 | 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]) { |
1356 | 1375 | start = arrays[it][positions[it]].lev;
|
1357 | 1376 | }
|
1358 | 1377 | }
|
|
1362 | 1381 | function mergeArrays(arrays) {
|
1363 | 1382 | var ret = [];
|
1364 | 1383 | var positions = [];
|
| 1384 | + var notDuplicates = {}; |
1365 | 1385 |
|
1366 | 1386 | for (var x = 0; x < arrays.length; ++x) {
|
1367 | 1387 | positions.push(0);
|
1368 | 1388 | }
|
1369 | 1389 | while (ret.length < MAX_RESULTS) {
|
1370 |
| - var smallest = getSmallest(arrays, positions); |
| 1390 | + var smallest = getSmallest(arrays, positions, notDuplicates); |
| 1391 | + |
1371 | 1392 | if (smallest === null) {
|
1372 | 1393 | break;
|
1373 | 1394 | }
|
1374 | 1395 | for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
|
1375 | 1396 | 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]) { |
1377 | 1399 | ret.push(arrays[x][positions[x]]);
|
| 1400 | + notDuplicates[arrays[x][positions[x]].fullPath] = true; |
1378 | 1401 | positions[x] += 1;
|
1379 | 1402 | }
|
1380 | 1403 | }
|
|
0 commit comments