用户搜索使用MySQL LIKE还是集成搜索引擎(如solr、sphinx、lucene等)?
在我的 mysql 数据库中,我有一个由 37,000 个(或大约)用户组成的用户表。
当用户在网站上搜索另一个用户时,我执行一个简单的 like 通配符(即 LIKE '{name}%})来返回找到的用户。
使用像 solr 这样的搜索引擎来进行“LIKE”搜索会更高效、更快吗?此外?我相信 solr 我可以使用通配符查询(http://www.lucidimagination.com/blog/2009/09/08/auto-suggest-from-popular-queries-using-edgengrams/)
说实话,事实并非如此目前使用 LIKE 查询速度很慢,但是随着用户数量的增长,它会变得更慢。非常感谢任何提示或建议。
In my mysql db I have a user table consisting of 37,000 (or thereabouts) users.
When a user search for another user on the site, I perform a simple like wildcard (i.e. LIKE '{name}%}) to return the users found.
Would it be more efficient and quicker to use a search engine such a solr to do my 'LIKE' searches? furthermore? I believe in solr I can use wildcard queries (http://www.lucidimagination.com/blog/2009/09/08/auto-suggest-from-popular-queries-using-edgengrams/)
To be honest, it's not that slow at the moment using a LIKE query however as the number of users grows it'll become slower. Any tips or advice is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
大约一个月前我们也遇到过类似的情况,我们的数据库大约是 33k~ 并且由于我们的引擎是 InnoDB,我们无法利用 MySQL 全文搜索功能(这很直率)。
我们决定实施 sphinxsearch (http://www.sphinxsearch.com),结果给我们留下了深刻的印象(我已经成为它的“粉丝”)。
如果我们对所有行的许多列(左连接负载)进行大型索引搜索,我们实际上将相对于 MySQL 'LIKE' 对应项的查询响应时间减半。
尽管我们使用它的时间不长 - 如果您要为未来的可扩展性进行构建,我会推荐 sphinx。
We had a similar situation about a month ago, our database is roughly around 33k~ and due to the fact our engine was InnoDB we could not utilize the MySQL full-text search feature (that and it being quite blunt).
We decided to implement sphinxsearch (http://www.sphinxsearch.com) and we're really impressed with the results (me becoming quite a 'fanboy' of it).
If we do a large index search with many columns (loads of left joins) of all our rows we actually halved the query response time against the MySQL 'LIKE' counterpart.
Although we havn't used it for long - If you're going to build for future scailablity i'd recommend sphinx.
如果搜索词必须至少有 3 个字符才能开始搜索,并使用 3 个字符的索引大小为搜索列建立索引,则可以加快速度。
you can speed up if the searchword must have minimum 3 chars to start the search and index your search column with a index size of 3 chars.
它实际上已经内置到 MySQL 中:http://dev。 mysql.com/doc/refman/5.0/en/fulltext-search.html
It's actually already built-in to MySQL: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
我们使用 solr 来实现此目的,因为即使索引了数百万个文档,您也可以在 1-2 毫秒内进行搜索。我们使用 数据导入处理程序 镜像我们的 mysql 实例,然后在 Solr 上搜索。
正如 neville 指出的,全文搜索是内置在 mysql 中的,但是 solr 的性能要好得多,因为它是作为全文搜索引擎而诞生的
we're using solr for this purpose, since you can search in 1-2 ms even with milions of documents indexed. we're mirroring our mysql instance with Data Import Handler and then we search on Solr.
as neville pointed out, full text searches are built-in in mysql, but solr performances are way better, since it's born as a full text search engine