Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Limit search API calls rate when typing in the search portal widget
luccioman79643c40bfe6
diff --git a/htroot/portalsearch/yacy-portalsearch.js b/htroot/portalsearch/yacy-portalsearch.jsindex 92ac6338f..42d76f26f 100644--- a/htroot/portalsearch/yacy-portalsearch.js+++ b/htroot/portalsearch/yacy-portalsearch.js@@ -184,7 +184,7 @@ function yrun() {$("#ypopup").dialog('close');} else { // Else fire up a search request and remeber the current search termycurr = $("#yquery").getValue();- yacysearch(true);+ debouncedYacysearch(true);}return false;});@@ -205,6 +205,24 @@ function yrun() {});}+var suggestTimeoutId = null;++/**+ * Debounce wrapper to limit the rate of calls to the backend search service.+ * @param clear when true, clear the results popup+ */+function debouncedYacysearch(clear) {+ if(suggestTimeoutId != null) {+ /* Remove delayed call not yet done */+ clearTimeout(suggestTimeoutId);+ }++ /* Limit the rate of calls to the search API by adding a delay before effective call */+ suggestTimeoutId = setTimeout(function() {+ yacysearch(clear);+ }, 400);+}+function yacysearch(clear) {var url = yconf.url + '/yacysearch.json?callback=?' // JSONP (cross domain) request URL//var url = yconf.url + '/solr/select?wt=yjson&callback=?' // JSONP (cross domain) request URL