Implement an instant thread search algorithm

So, I would like to know what constitutes a general algorithm for implementing quick search not . Not specifically on the Internet, but even in the desktop / winforms application.

Correct me if I am wrong, but you cannot send asynchronous calls every time you press a key on the right? (Not sure how Google instantly manages this ). This would create a crazy load on the database / storage, etc.

I was thinking of something like this:

  • Fire Alarm Timer every xxx milliseconds
  • On, Turn off input, Turn off timer, and send an asynchronous call to search.
  • When the call returns, displays the results, allows input, starts the timer

Is this the way it is usually processed, or is there a better way?

+3
source share
1 answer

Search queries are usually small, so the increased load on the server may not be as significant as you think. Sending a request for every keystroke should be great if you keep a limit on the length of requests.

In any case, this is a server that knows how it is loaded, so the place to control the download is on the server side. For example, you could follow a strategy something like this:

On the client:

  • When changing the search text, send it to the server.
  • When the server sends some results, refresh the page.

On the server, when the request is received from the client:

  • If I am already processing a request from this client, cancel the old request.
  • , .
  • , .
+2

Source: https://habr.com/ru/post/1776902/


All Articles