Simply setup the delayed invocation with setTimeout(), then remove it again on every event with clearTimeout()
HTML
Javascript
var timeout = null;
function doDelayedSearch(val) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
doSearch(val); //this is your existing function
}, 2000);
}