How can live search / search suggestions be implemented using Dojo? How can live search / search suggestions be implemented using Dojo? ajax ajax

How can live search / search suggestions be implemented using Dojo?


I implemented it 5 years ago when Dojo was at 0.2:

While the code is ancient, it is trivial, and hopefully it'll give you ideas on how to attack it. The rough sketch:

  • Attach an event handler to your input box, which is triggered on changes — use "onkeyup" to detect a change in the input box.
  • Wait until user stopped typing by setting a timer in your event handler, if it is not set yet. 200-500ms are good waiting times.
    • The timeout plays a dual role:
      • It throttles our requests to a server to prevent overloading.
      • It plays on our perception of time and our typing habits.
  • If our timeout is up, and we don't wait for a server ⇒ send server a string we have so far.
  • If we are still waiting for a server, cancel the request and ask again.
    • This part is app-specific: we don't want to overload a server, and sometimes a server cannot handle broken connections well.
    • In the example I don't cancel the XHR call, but wait it to finish first before submitting new request.
  • Server responds with relevant results, which are promptly shown.

In the blog post I implemented it as a widget. Obviously the exact packaging is up to you.