mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
generated docs: prioritized sort ranking
This commit is contained in:
parent
7688100b17
commit
2e26aaa70c
@ -280,10 +280,10 @@
|
||||
}
|
||||
}
|
||||
typesList.sort(function(a, b) {
|
||||
return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase());
|
||||
return operatorCompare(a.name, b.name);
|
||||
});
|
||||
fnsList.sort(function(a, b) {
|
||||
return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase());
|
||||
return operatorCompare(a.name, b.name);
|
||||
});
|
||||
|
||||
if (typesList.length !== 0) {
|
||||
@ -488,11 +488,9 @@
|
||||
function onSearchKeyDown(ev) {
|
||||
switch (ev.which) {
|
||||
case 13:
|
||||
var liDom = null;
|
||||
if (domListSearchResults.children.length === 1) {
|
||||
var liDom = domListSearchResults.children[curSearchIndex];
|
||||
if (liDom == null && domListSearchResults.children.length !== 0) {
|
||||
liDom = domListSearchResults.children[0];
|
||||
} else {
|
||||
liDom = domListSearchResults.children[curSearchIndex];
|
||||
}
|
||||
if (liDom != null) {
|
||||
var aDom = liDom.children[0];
|
||||
@ -604,29 +602,49 @@
|
||||
|
||||
var decl = zigAnalysis.decls[declIndex];
|
||||
var lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1];
|
||||
var searchText = lastPkgName + "." + canonPath.declNames.join('.');
|
||||
var fullPathSearchText = lastPkgName + "." + canonPath.declNames.join('.');
|
||||
var astNode = zigAnalysis.astNodes[decl.src];
|
||||
var fileAndDocs = zigAnalysis.files[astNode.file];
|
||||
if (astNode.docs != null) {
|
||||
searchText += "\n" + astNode.docs;
|
||||
fileAndDocs += "\n" + astNode.docs;
|
||||
}
|
||||
var file = zigAnalysis.files[astNode.file];
|
||||
searchText += "\n" + file;
|
||||
var fullPathSearchTextLower = fullPathSearchText;
|
||||
if (ignoreCase) {
|
||||
searchText = searchText.toLowerCase();
|
||||
fullPathSearchTextLower = fullPathSearchTextLower.toLowerCase();
|
||||
fileAndDocs = fileAndDocs.toLowerCase();
|
||||
}
|
||||
|
||||
var points = 0;
|
||||
for (var termIndex = 0; termIndex < terms.length; termIndex += 1) {
|
||||
var term = terms[termIndex];
|
||||
if (searchText.indexOf(term) >= 0) {
|
||||
|
||||
// exact, case sensitive match of full decl path
|
||||
if (fullPathSearchText === term) {
|
||||
points += 4;
|
||||
continue;
|
||||
} else {
|
||||
continue decl_loop;
|
||||
}
|
||||
// exact, case sensitive match of just decl name
|
||||
if (decl.name == term) {
|
||||
points += 3;
|
||||
continue;
|
||||
}
|
||||
// substring, case insensitive match of full decl path
|
||||
if (fullPathSearchTextLower.indexOf(term) >= 0) {
|
||||
points += 2;
|
||||
continue;
|
||||
}
|
||||
if (fileAndDocs.indexOf(term) >= 0) {
|
||||
points += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
continue decl_loop;
|
||||
}
|
||||
|
||||
matchedItems.push({
|
||||
decl: decl,
|
||||
path: canonPath,
|
||||
points: points,
|
||||
});
|
||||
}
|
||||
|
||||
@ -634,6 +652,8 @@
|
||||
resizeDomList(domListSearchResults, matchedItems.length, '<li><a href="#"></a></li>');
|
||||
|
||||
matchedItems.sort(function(a, b) {
|
||||
var cmp = operatorCompare(b.points, a.points);
|
||||
if (cmp != 0) return cmp;
|
||||
return operatorCompare(a.decl.name, b.decl.name);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user