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