什么是实现服务器自动完成的最好方法? [英] What's the best way to implement AutoComplete in the server?

查看:157
本文介绍了什么是实现服务器自动完成的最好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很简单的人。使自动完成在Web应用程序的客户端美丽很简单。有很多插件。

This question is easy people. Make autocomplete beautiful in the client side of a web app is simple. There are a lot of plugins.

不过,在背面,在服务器端,有什么做的最好方法是什么?我不喜欢这个主意打到数据库与用户pssed每个键$ P $。

But, in the backside, in the server side, what's the best way to do it? I don't like the idea to hit the DB with each keypressed by the user.

我一直在思考狮身人面像,或者一些全文搜索引擎并行运行,从您的网站。

I've been thinking about sphinx, or some full-text search engine running parallel from your site.

例如,如果我有一个PHP(高流量)的网站,我可以创造一个平行的Python脚本,从我的自动完成文本框HTTP请求。然后,当用户是pressing在客户端侧的键,AJAX请求被定向到Python脚本,可以使用一个特殊的策略

For example, if i have a PHP (high traffic) web site, i can create a parallel python script that get http requests from my "autocomplete textboxes". Then, when a user is pressing a key in the client side, the AJAX requests are directed to that python script that can use a special strategy.

什么是你的aproach?

What's your aproach?

一些约定:


  • 尝试不打DB。我的意思是,拿
    请求并做一些SELECT *
    从foo WHERE酒吧LIKEREQ%不是
    一个很好的答案。它可能是一个好
    策略,但我知道如何做到这一点。*

  • 复制的数据可以是一个不错的选择。

推荐答案

我不同意,你需要有一些更好的解决方案。 Apache Solr实现有一个建议功能,您可以使用pretty好。如果你的数据集是小然后把所有的数据在内存中,只是做一个简单的循环。

I do agree that you need to have some better solution. Apache solr has a "suggestion" feature that you can use pretty well. If your data set is small then put all the data in memory and just do a simple loop.

在前端,我建议使用的setTimeout()发射Ajax调用之前等待200ms左右。如果在200毫秒时,将触发另一击键,则取消最后超时而启动另一个。这是一个非常干净的解决方案,其中它不会击中每次击键的分贝。我已经在过去使用它和它的作品真的很好。

On the front end, I recommend using setTimeout() to wait for about 200ms before firing the ajax call. If in that 200ms, another keystroke is triggered, then cancel the last timeout and start another one. This is a really clean solution where it wouldn't hit the db with each keystroke. I have used it in the past and it works really well.

这说明了Solr的使用jQuery,以及如何创建一个自动完成的非常好。
<一href=\"http://www.mattweber.org/2009/05/02/solr-autosuggest-with-termscomponent-and-jquery/\">http://www.mattweber.org/2009/05/02/solr-autosuggest-with-termscomponent-and-jquery/

This explains solr with jquery and how to create an autocomplete really well. http://www.mattweber.org/2009/05/02/solr-autosuggest-with-termscomponent-and-jquery/

这篇关于什么是实现服务器自动完成的最好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆