移动 Safari 中性能最高的实时搜索技术

发布于 2024-12-02 17:27:53 字数 537 浏览 0 评论 0原文

我正在构建一个针对 webkit 的移动 Web 应用程序。我需要对大约 5000 个用户的数据库执行实时搜索(按按键)。

我尝试了多种不同的技术:

  1. 在页面加载时,进行 AJAX 调用,加载所有 5000 个用户的内存中表示,并在客户端上查询它们。我尝试发送 JSON,结果证明它太大了,还有一个自定义分隔字符串,然后使用 split() 对其进行解析。这更好,但最终针对这组用户的搜索速度很慢。
  2. 我尝试使用传统的 AJAX 调用,该调用将根据查询返回用户,同时也使用自定义分隔字符串技术。这更好,但我被迫对其进行调整,以便仅使用至少 3 个字符执行搜索。这不是最佳选择,因为我希望能够在 1 个字符后开始过滤。我还可以限制调用,这样就不会在特定阈值内的每次击键都会触发请求。这可能有助于提高性能,但我不想摆弄这类事情。

如果你尝试一下 Facebook 移动版的朋友搜索,它在这方面做得非常好。搜索立即发生,并在 1 个字符后触发。

我的问题是,有人对更快地实时搜索移动应用程序有任何建议吗?我应该查看 localStorage 吗?这可靠、可行吗?

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 split(). 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千紇 2024-12-09 17:27:53

有什么原因不能使用二分搜索吗?您要查找的名称应该位于一个块中。如果您想要搜索名字和姓氏,您可以创建按姓氏排序的数据的第二个副本,并在两个集合中查找。

解决此类问题的一些有用但更复杂的数据结构包括

:维基/Directed_acycl_word_graph
http://en.wikipedia.org/wiki/Trie

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文