Simply setup the delayed invocation with setTimeout(), then remove it again on every event with clearTimeout()
HTML
<form action="" method="post" accept-charset="utf-8">
<p><input type="text" name="q" id="q" value="" onkeyup="doDelayedSearch(this.value)" /></p>
</form>
Javascript
var timeout = null;
function doDelayedSearch(val) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
doSearch(val); //this is your existing function
}, 2000);
}