efficient serverside autocomplete

后端 未结 3 461
醉梦人生
醉梦人生 2021-02-01 10:10

First off all I know:

Premature optimization is the root of all evil

But I think wrong autocomplete can really blow up your site.

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 10:53

    I will no comply with your requirements and obviously the numbers of scale will depend on hardware, size of the DB, architecture of the app, and several other items. You must test it yourself.

    But I will tell you the method I've used with success:

    • Use a simple SQL like for example: SELECT name FROM users WHERE name LIKE al%. but use TOP 100 to limit the number of results.
    • Cache the results and maintain a list of terms that are cached
    • When a new request comes in, first check in the list if you have the term (or part of the term cached).
    • Keep in mind that your cached results are limited, some you may need to do a SQL query if the term remains valid at the end of the result (I mean valid if the latest result match with the term.

    Hope it helps.

提交回复
热议问题