Skip to content

Commit

Permalink
Limit search API calls rate when typing in the search portal widget
Browse files Browse the repository at this point in the history
  • Loading branch information
luccioman committed Aug 28, 2018
1 parent 39dd29a commit 79643c4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion htroot/portalsearch/yacy-portalsearch.js
Expand Up @@ -184,7 +184,7 @@ function yrun() {
$("#ypopup").dialog('close');
} else { // Else fire up a search request and remeber the current search term
ycurr = $("#yquery").getValue();
yacysearch(true);
debouncedYacysearch(true);
}
return false;
});
Expand All @@ -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
Expand Down

0 comments on commit 79643c4

Please sign in to comment.