rustdoc: Clean the initSearch routine up.

This commit is contained in:
Kang Seonghoon 2014-04-09 02:47:52 +09:00 committed by Alex Crichton
parent dd00bf3791
commit 34ece7ad71

View File

@ -137,8 +137,6 @@
val = valLower,
typeFilter = query.type,
results = [],
aa = 0,
bb = 0,
split = valLower.split("::");
//remove empty keywords
@ -150,16 +148,16 @@
}
// quoted values mean literal search
bb = searchWords.length;
var nSearchWords = searchWords.length;
if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
val.charAt(val.length - 1) === val.charAt(0))
{
val = val.substr(1, val.length - 2);
for (aa = 0; aa < bb; aa += 1) {
if (searchWords[aa] === val) {
for (var i = 0; i < nSearchWords; i += 1) {
if (searchWords[i] === val) {
// filter type: ... queries
if (!typeFilter || typeFilter === searchIndex[aa].ty) {
results.push([aa, -1]);
if (!typeFilter || typeFilter === searchIndex[i].ty) {
results.push({id: i, index: -1});
}
}
if (results.length === max) {
@ -170,14 +168,14 @@
// gather matching search results up to a certain maximum
val = val.replace(/\_/g, "");
for (var i = 0; i < split.length; i++) {
for (aa = 0; aa < bb; aa += 1) {
if (searchWords[aa].indexOf(split[i]) > -1 ||
searchWords[aa].indexOf(val) > -1 ||
searchWords[aa].replace(/_/g, "").indexOf(val) > -1)
for (var j = 0; j < nSearchWords; j += 1) {
if (searchWords[j].indexOf(split[i]) > -1 ||
searchWords[j].indexOf(val) > -1 ||
searchWords[j].replace(/_/g, "").indexOf(val) > -1)
{
// filter type: ... queries
if (!typeFilter || typeFilter === searchIndex[aa].ty) {
results.push([aa, searchWords[aa].replace(/_/g, "").indexOf(val)]);
if (!typeFilter || typeFilter === searchIndex[j].ty) {
results.push({id: j, index: searchWords[j].replace(/_/g, "").indexOf(val)});
}
}
if (results.length === max) {
@ -187,13 +185,12 @@
}
}
bb = results.length;
for (aa = 0; aa < bb; aa += 1) {
results[aa].push(searchIndex[results[aa][0]].ty);
results[aa].push(searchIndex[results[aa][0]].path);
results[aa].push(searchIndex[results[aa][0]].name);
results[aa].push(searchIndex[results[aa][0]].parent);
results[aa].push(searchIndex[results[aa][0]].crate);
var nresults = results.length;
for (var i = 0; i < nresults; i += 1) {
results[i].word = searchWords[results[i].id];
results[i].item = searchIndex[results[i].id] || {};
results[i].ty = results[i].item.ty;
results[i].path = results[i].item.path;
}
// if there are no results then return to default and fail
if (results.length === 0) {
@ -202,31 +199,31 @@
// sort by exact match
results.sort(function search_complete_sort0(aaa, bbb) {
if (searchWords[aaa[0]] === valLower &&
searchWords[bbb[0]] !== valLower) {
if (aaa.word === valLower &&
bbb.word !== valLower) {
return 1;
}
});
// first sorting attempt
// sort by item name length
results.sort(function search_complete_sort1(aaa, bbb) {
if (searchWords[aaa[0]].length > searchWords[bbb[0]].length) {
if (aaa.word.length > bbb.word.length) {
return 1;
}
});
// second sorting attempt
// sort by item name
results.sort(function search_complete_sort1(aaa, bbb) {
if (searchWords[aaa[0]].length === searchWords[bbb[0]].length &&
searchWords[aaa[0]] > searchWords[bbb[0]]) {
if (aaa.word.length === bbb.word.length &&
aaa.word > bbb.word) {
return 1;
}
});
// third sorting attempt
// sort by index of keyword in item name
if (results[0][1] !== -1) {
if (results[0].index !== -1) {
results.sort(function search_complete_sort1(aaa, bbb) {
if (aaa[1] > bbb[1] && bbb[1] === 0) {
if (aaa.index > bbb.index && bbb.index === 0) {
return 1;
}
});
@ -234,38 +231,38 @@
// fourth sorting attempt
// sort by type
results.sort(function search_complete_sort3(aaa, bbb) {
if (searchWords[aaa[0]] === searchWords[bbb[0]] &&
aaa[2] > bbb[2]) {
if (aaa.word === bbb.word &&
aaa.ty > bbb.ty) {
return 1;
}
});
// fifth sorting attempt
// sort by path
results.sort(function search_complete_sort4(aaa, bbb) {
if (searchWords[aaa[0]] === searchWords[bbb[0]] &&
aaa[2] === bbb[2] && aaa[3] > bbb[3]) {
if (aaa.word === bbb.word &&
aaa.ty === bbb.ty && aaa.path > bbb.path) {
return 1;
}
});
// sixth sorting attempt
// remove duplicates, according to the data provided
for (aa = results.length - 1; aa > 0; aa -= 1) {
if (searchWords[results[aa][0]] === searchWords[results[aa - 1][0]] &&
results[aa][2] === results[aa - 1][2] &&
results[aa][3] === results[aa - 1][3])
for (var i = results.length - 1; i > 0; i -= 1) {
if (results[i].word === results[i - 1].word &&
results[i].ty === results[i - 1].ty &&
results[i].path === results[i - 1].path)
{
results[aa][0] = -1;
results[i].id = -1;
}
}
for (var i = 0; i < results.length; i++) {
var result = results[i],
name = result[4].toLowerCase(),
path = result[3].toLowerCase(),
parent = allPaths[result[6]][result[5]];
name = result.item.name.toLowerCase(),
path = result.item.path.toLowerCase(),
parent = allPaths[result.item.crate][result.item.parent];
var valid = validateResult(name, path, split, parent);
if (!valid) {
result[0] = -1;
result.id = -1;
}
}
return results;
@ -495,8 +492,8 @@
resultIndex = execQuery(query, 20000, index);
len = resultIndex.length;
for (i = 0; i < len; i += 1) {
if (resultIndex[i][0] > -1) {
obj = searchIndex[resultIndex[i][0]];
if (resultIndex[i].id > -1) {
obj = searchIndex[resultIndex[i].id];
filterdata.push([obj.name, obj.ty, obj.path, obj.desc]);
results.push(obj);
}
@ -580,7 +577,6 @@
// Draw a convenient sidebar of known crates if we have a listing
if (rootPath == '../') {
console.log('here');
var sidebar = $('.sidebar');
var div = $('<div>').attr('class', 'block crate');
div.append($('<h2>').text('Crates'));