What I am trying to do here in flex is to perform a search as the user types in the search keywords in a textinput. A query runs in a background, fetches the data from sqlite and displays it perfectly fine. The problem is with a large database/large result set. When I query >10000 rows of data, the delay is quite evident. This is a cause of concern when the user keeps typing in and a query is fired for each keystroke.
Example:- lets say the users wants to search for keyword 'hello'. As the user types in, a keyup event attached to the textinput fires queries in the background. So here, there will be 5 keyUp events fired i.e. 5 queries.
What I am trying to achieve here is a bit of performance and cutting loose the irrelevant searches by trying to add a delay to the keyUp event.
<s:TextInput id="searchBox" keyUp="search()"/>
public function search():void{
searchForKeyWord(StringUtil.trim(searchBox.text));//fires a SQL query
}
Can someone help me understand as to how would I be able to add a delay here (lets say of 2 seconds) before the query gets fired. After 2 seconds, if the input has changed, then there is a delay of 2 more seconds and so on, until the search keyword remains constant for 2 seconds.
Please let me know if there is a better way to do things (rather than adding timers etc).