improve search perf: trim search results
parent
f76d59ef76
commit
297452cf67
|
@ -576,6 +576,7 @@
|
|||
<div id="sectSearchResults" class="hidden">
|
||||
<h2>Search Results</h2>
|
||||
<ul id="listSearchResults"></ul>
|
||||
<p id="sectSearchAllResultsLink" class="hidden"><a href="">show all results</a></p>
|
||||
</div>
|
||||
<div id="sectSearchNoResults" class="hidden">
|
||||
<h2>No Results Found</h2>
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
var domSectSearchResults = document.getElementById("sectSearchResults");
|
||||
var domListSearchResults = document.getElementById("listSearchResults");
|
||||
var domSectSearchNoResults = document.getElementById("sectSearchNoResults");
|
||||
var domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");
|
||||
var domSectInfo = document.getElementById("sectInfo");
|
||||
var domTdTarget = document.getElementById("tdTarget");
|
||||
var domTdZigVer = document.getElementById("tdZigVer");
|
||||
|
@ -42,6 +43,7 @@
|
|||
var domHelpModal = document.getElementById("helpDialog");
|
||||
|
||||
var searchTimer = null;
|
||||
var searchTrimResults = true;
|
||||
var escapeHtmlReplacements = { "&": "&", '"': """, "<": "<", ">": ">" };
|
||||
|
||||
var typeKinds = indexTypeKinds();
|
||||
|
@ -82,6 +84,8 @@
|
|||
var nodesToCallsMap = indexNodesToCalls();
|
||||
|
||||
domSearch.addEventListener('keydown', onSearchKeyDown, false);
|
||||
domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);
|
||||
|
||||
window.addEventListener('hashchange', onHashChange, false);
|
||||
window.addEventListener('keydown', onWindowKeyDown, false);
|
||||
onHashChange();
|
||||
|
@ -113,6 +117,7 @@
|
|||
domSectFields.classList.add("hidden");
|
||||
domSectSearchResults.classList.add("hidden");
|
||||
domSectSearchNoResults.classList.add("hidden");
|
||||
domSectSearchAllResultsLink.classList.add("hidden");
|
||||
domSectInfo.classList.add("hidden");
|
||||
domHdrName.classList.add("hidden");
|
||||
domSectNav.classList.add("hidden");
|
||||
|
@ -1810,6 +1815,13 @@
|
|||
domHelpModal.focus();
|
||||
}
|
||||
|
||||
function onClickSearchShowAllResults(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
searchTrimResults = false;
|
||||
onHashChange();
|
||||
}
|
||||
|
||||
function clearAsyncSearch() {
|
||||
if (searchTimer != null) {
|
||||
clearTimeout(searchTimer);
|
||||
|
@ -1819,6 +1831,7 @@
|
|||
|
||||
function startAsyncSearch() {
|
||||
clearAsyncSearch();
|
||||
searchTrimResults = true;
|
||||
searchTimer = setTimeout(startSearch, 10);
|
||||
}
|
||||
function startSearch() {
|
||||
|
@ -1897,6 +1910,13 @@
|
|||
return operatorCompare(a.decl.name, b.decl.name);
|
||||
});
|
||||
|
||||
var searchTrimmed = false
|
||||
var searchTrimResultsMaxItems = 200
|
||||
if (searchTrimResults && matchedItems.length > searchTrimResultsMaxItems) {
|
||||
matchedItems = matchedItems.slice(0, searchTrimResultsMaxItems)
|
||||
searchTrimmed = true
|
||||
}
|
||||
|
||||
var domListSearchResultsFragment = createDomListFragment(matchedItems.length, '<li><a href="#"></a></li>');
|
||||
for (var i = 0; i < matchedItems.length; i += 1) {
|
||||
var liDom = domListSearchResultsFragment.children[i];
|
||||
|
@ -1911,6 +1931,10 @@
|
|||
domListSearchResults.appendChild(domListSearchResultsFragment);
|
||||
domSectSearchResults.classList.remove("hidden");
|
||||
|
||||
if (searchTrimmed) {
|
||||
domSectSearchAllResultsLink.classList.remove("hidden");
|
||||
}
|
||||
|
||||
renderSearchCursor();
|
||||
} else {
|
||||
domSectSearchNoResults.classList.remove("hidden");
|
||||
|
|
Loading…
Reference in New Issue