Improve rustdoc search type filtering.
This commit is contained in:
@@ -113,8 +113,8 @@ r##"<!DOCTYPE html>
|
|||||||
<p>
|
<p>
|
||||||
Accepted types are: <code>fn</code>, <code>mod</code>,
|
Accepted types are: <code>fn</code>, <code>mod</code>,
|
||||||
<code>struct</code>, <code>enum</code>,
|
<code>struct</code>, <code>enum</code>,
|
||||||
<code>trait</code>, <code>typedef</code> (or
|
<code>trait</code>, <code>type</code>, <code>macro</code>,
|
||||||
<code>tdef</code>).
|
and <code>const</code>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -230,6 +230,28 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function typePassesFilter(filter, type) {
|
||||||
|
// No filter
|
||||||
|
if (filter < 0) return true;
|
||||||
|
|
||||||
|
// Exact match
|
||||||
|
if (filter === type) return true;
|
||||||
|
|
||||||
|
// Match related items
|
||||||
|
var name = itemTypes[type];
|
||||||
|
switch (itemTypes[filter]) {
|
||||||
|
case "constant":
|
||||||
|
return (name == "associatedconstant");
|
||||||
|
case "fn":
|
||||||
|
return (name == "method" || name == "tymethod");
|
||||||
|
case "type":
|
||||||
|
return (name == "primitive");
|
||||||
|
}
|
||||||
|
|
||||||
|
// No match
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// quoted values mean literal search
|
// quoted values mean literal search
|
||||||
var nSearchWords = searchWords.length;
|
var nSearchWords = searchWords.length;
|
||||||
if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
|
if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
|
||||||
@@ -239,7 +261,7 @@
|
|||||||
for (var i = 0; i < nSearchWords; ++i) {
|
for (var i = 0; i < nSearchWords; ++i) {
|
||||||
if (searchWords[i] === val) {
|
if (searchWords[i] === val) {
|
||||||
// filter type: ... queries
|
// filter type: ... queries
|
||||||
if (typeFilter < 0 || typeFilter === searchIndex[i].ty) {
|
if (typePassesFilter(typeFilter, searchIndex[i].ty)) {
|
||||||
results.push({id: i, index: -1});
|
results.push({id: i, index: -1});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,7 +307,7 @@
|
|||||||
searchWords[j].replace(/_/g, "").indexOf(val) > -1)
|
searchWords[j].replace(/_/g, "").indexOf(val) > -1)
|
||||||
{
|
{
|
||||||
// filter type: ... queries
|
// filter type: ... queries
|
||||||
if (typeFilter < 0 || typeFilter === searchIndex[j].ty) {
|
if (typePassesFilter(typeFilter, searchIndex[j].ty)) {
|
||||||
results.push({
|
results.push({
|
||||||
id: j,
|
id: j,
|
||||||
index: searchWords[j].replace(/_/g, "").indexOf(val),
|
index: searchWords[j].replace(/_/g, "").indexOf(val),
|
||||||
@@ -295,7 +317,7 @@
|
|||||||
} else if (
|
} else if (
|
||||||
(lev_distance = levenshtein(searchWords[j], val)) <=
|
(lev_distance = levenshtein(searchWords[j], val)) <=
|
||||||
MAX_LEV_DISTANCE) {
|
MAX_LEV_DISTANCE) {
|
||||||
if (typeFilter < 0 || typeFilter === searchIndex[j].ty) {
|
if (typePassesFilter(typeFilter, searchIndex[j].ty)) {
|
||||||
results.push({
|
results.push({
|
||||||
id: j,
|
id: j,
|
||||||
index: 0,
|
index: 0,
|
||||||
@@ -451,11 +473,9 @@
|
|||||||
var matches, type, query, raw = $('.search-input').val();
|
var matches, type, query, raw = $('.search-input').val();
|
||||||
query = raw;
|
query = raw;
|
||||||
|
|
||||||
matches = query.match(/^(fn|mod|struct|enum|trait|t(ype)?d(ef)?)\s*:\s*/i);
|
matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
type = matches[1].replace(/^td$/, 'typedef')
|
type = matches[1].replace(/^const$/, 'constant');
|
||||||
.replace(/^tdef$/, 'typedef')
|
|
||||||
.replace(/^typed$/, 'typedef');
|
|
||||||
query = query.substring(matches[0].length);
|
query = query.substring(matches[0].length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user