开发者

Most performant live search technique for mobile safari

开发者 https://www.devze.com 2023-04-01 02:30 出处:网络
I am building a mobile web application that targets webkit. I have a requirement to perform a live search (on keypress) against a database of ~5000 users.

I am building a mobile web application that targets webkit. I have a requirement to perform a live search (on keypress) against a database of ~5000 users.

I've tried a number of different techniques:

  1. On page load, making an AJAX call which loads an in-memory representation of all 5000 users, and querying them on the client. I tried sending JSON, which proved to be too large, and also a custom delimited string, which was then parsed using sp开发者_如何学Pythonlit(). This was better, but ultimately searches against this array of users was slow.
  2. I tried using a conventional AJAX call, which would return users based on a query, also using the custom delimited string technique. This was better, but I was forced to tune it so that searches were only performed with a minimum of 3 characters. This is not optimal, as I would like to be able to start filtering after 1 character. I could also throttle the calls so that not every keystroke within a certain threshold triggered a request. This could help with performance, but I'd rather not have to fiddle with that sort of thing.

Facebook mobile does this very well if you try their friend search. Searches happen instantaneously, and are triggered after 1 character.

My question is, does anyone have any suggestions for faster live searches for a mobile app? Should I be looking at localStorage? Is this reliable, feasible?


Is there any reason you can't use a binary search? The names you're looking for should be in a block. If you want first and last name search, you could create a second copy of the data sorted by last name and look in both sets.

Some helpful but more complicated data structures that address this type of problem include:

http://en.wikipedia.org/wiki/Directed_acyclic_word_graph http://en.wikipedia.org/wiki/Trie

0

精彩评论

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

关注公众号