mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
Limit the rate of calls to the suggest API when typing in search field
This commit is contained in:
parent
84d82bfdd7
commit
1dfd3e9dde
|
@ -6,12 +6,24 @@
|
|||
#%env/templates/metas.template%#
|
||||
<link rel="alternate" type="application/rss+xml" title="Search for #[former]#" href="yacysearch.rss?query=#[former]#" />
|
||||
<link rel="search" type="application/opensearchdescription+xml" title="YaCy '#[clientname]#'" href="opensearchdescription.xml" />
|
||||
<script type="text/javascript" src="env/bootstrap/js/typeahead.jquery.min.js"></script>
|
||||
<script type="text/javascript" src="env/bootstrap/js/typeahead.jquery.js"></script>
|
||||
<script type="text/javascript" src="js/html.js"></script>
|
||||
<script type="text/javascript">
|
||||
var suggestMatcher = function() {
|
||||
return function opensearch(q, cb) {
|
||||
$.getJSON("suggest.json?q=" + q, function(data) {
|
||||
$(document).ready(function() {
|
||||
var suggestTimeoutId = null;
|
||||
|
||||
/* Configure the search input field to get suggestions on key strokes */
|
||||
$('#search').typeahead({hint:false,highlight:true,minLength:1}, {
|
||||
name: 'states',
|
||||
displayKey: 'value',
|
||||
source: function(query, render) {
|
||||
if(suggestTimeoutId != null) {
|
||||
/* Remove delayed call not yet done */
|
||||
clearTimeout(suggestTimeoutId);
|
||||
}
|
||||
/* Limit the rate of calls to the suggest API by adding a delay before effective call */
|
||||
suggestTimeoutId = setTimeout(function() {
|
||||
$.getJSON("suggest.json?q=" + query, function(data) {
|
||||
var parsed = [];
|
||||
for (var i = 0; i < data[1].length; i++) {
|
||||
var row = data[1][i];
|
||||
|
@ -23,15 +35,10 @@
|
|||
};
|
||||
};
|
||||
};
|
||||
cb(parsed);
|
||||
render(parsed);
|
||||
});
|
||||
};
|
||||
};
|
||||
$(document).ready(function() {
|
||||
$('#search').typeahead({hint:false,highlight:true,minLength:1}, {
|
||||
name: 'states',
|
||||
displayKey: 'value',
|
||||
source: suggestMatcher()
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -22,25 +22,6 @@
|
|||
<link rel="stylesheet" type="text/css" media="screen" href="env/yacysort.css" />
|
||||
#(/jsResort)#
|
||||
<script type="text/javascript">
|
||||
var suggestMatcher = function() {
|
||||
return function opensearch(q, cb) {
|
||||
$.getJSON("suggest.json?q=" + q, function(data) {
|
||||
var parsed = [];
|
||||
for (var i = 0; i < data[1].length; i++) {
|
||||
var row = data[1][i];
|
||||
if (row) {
|
||||
parsed[parsed.length] = {
|
||||
data: [row],
|
||||
value: row,
|
||||
result: row
|
||||
};
|
||||
};
|
||||
};
|
||||
cb(parsed);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
#(jsResort)#::
|
||||
$.get(
|
||||
|
@ -53,10 +34,35 @@
|
|||
);
|
||||
#(/jsResort)#
|
||||
|
||||
var suggestTimeoutId = null;
|
||||
|
||||
/* Configure the search input field to get suggestions on key strokes */
|
||||
$('#search').typeahead({hint:false,highlight:true,minLength:1}, {
|
||||
name: 'states',
|
||||
displayKey: 'value',
|
||||
source: suggestMatcher()
|
||||
source: function(query, render) {
|
||||
if(suggestTimeoutId != null) {
|
||||
/* Remove delayed call not yet done */
|
||||
clearTimeout(suggestTimeoutId);
|
||||
}
|
||||
/* Limit the rate of calls to the suggest API by adding a delay before effective call */
|
||||
suggestTimeoutId = setTimeout(function() {
|
||||
$.getJSON("suggest.json?q=" + query, function(data) {
|
||||
var parsed = [];
|
||||
for (var i = 0; i < data[1].length; i++) {
|
||||
var row = data[1][i];
|
||||
if (row) {
|
||||
parsed[parsed.length] = {
|
||||
data: [row],
|
||||
value: row,
|
||||
result: row
|
||||
};
|
||||
};
|
||||
};
|
||||
render(parsed);
|
||||
});
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue
Block a user