开发者

Type and search, how to improve the performance?

开发者 https://www.devze.com 2023-01-26 15:55 出处:网络
I want to implement somethings like searching on wiki, when I want to search \"app开发者_StackOverflow社区le\" , I type \"a\" it shows the words start from \"a\"... I know that it can implement when I

I want to implement somethings like searching on wiki, when I want to search "app开发者_StackOverflow社区le" , I type "a" it shows the words start from "a"... I know that it can implement when I type, I submit a SQL query to search the article start from "a", but when more and more query request, it become slow... ... Is there any performance turning technique on doing this kind of things? Thank you.


On the server-side you should cache the results, ideally in memory (e.g: Memcached). So if 10 people hit "a" it will be only one query to the database and 9 super fast data access from the memory.

As for the bandwidth optimization, you should send your data in JSON, or alternatively some custom data format. See this awesome article: Building Fast Client-side Searches


Not sure what version of SQL you are using, but a few assumptions:

  • You have an index on the field you are searching
  • You are only returning the needed field (like title), not SELECT *

What I would recommend considering is reducing the number of rows returned depending on the size of the search query, something like: (pseudo-code, don't know your SQL dialect)

if len(searchString)<=3
   select top 50 title from table order by title
else
   select title from table order by title

The smaller searches are likely to return many more rows, but most users are likely to type in several letters before then stop typing, so for the initial queries, don't return all of the rows.


Not a technical answer an maybe obvious, but for client side I think you can launch your search event not on the key press but after X millisecond after the key press and with the condition that nothing is changed.

So if I want search a "word" and i type "w" "o" "r" "d" in a speedy way you only make une request and obviously you can optimize that request SQL way

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号