最近遇到了一个问题,大数据量下的全文搜索,比较费时。
例如: 100W的数据下,想要搜索,使用where的话,有的时候耗时 20+ 秒。 无法忍受。
同时,100W 的数据,占用了至少1G的空间。 光是全盘扫描的话,也无法在1秒内完成。
所以,还得求助于索引(index)
记得在JAVA项目中,lucene 是个非常好的工具,貌似现在也是。不知道RAILS的世界中如何?
理想的工具应该是:
1. 有个针对中文的分词文件(现成的),就好像LUCENE的那样
2. 使用这个分词文件,对数据库的数据进行索引的生成
3. 每次查询时,先从索引中查,然后再根据索引的结果,找到数据库的记录
4. 显示结果。
或者(最理想的情况)
数据库本身就提供了一个索引的功能。我啥都不管,直接 ensureIndex(ooxx),然后就可以用了。仿佛不存在这个索引的中间层一样。直接操作数据库。
搜索了一下,进展如下:
Well, there's Ferret, which is a port of Lucene to Ruby. Also, Lucene is very easy to use from JRuby, if that's an option for you.
Depending on your needs, you might also want to take a look at Solr, which is a higher-level front-end built on Lucene. There is a Ruby interface, solr-ruby, that interacts with Solr via HTTP.
1. Lucene 在RUBY世界中的替代者是: Ferret. 不过
网站没打开。 github (
https://github.com/dbalmain/ferret) 则没问题。
2. Lucene 也有独立的server, 叫
Solr, 可以使用 solr-ruby 与之进行交互。
3. solr-ruby 已经过时了。对于Ruby, 使用 Rsolr, 对于Rails项目,使用 blacklight(
For the latest Ruby Solr library, use RSolr -
http://rubygems.org/gems/rsolr
For the latest Rails application plugin, use Blacklight -
http://projectblacklight.org 链接打不开. 给作者发了信,结果对方说短期内不会维护了。 ( Hi Shen,
The site won't be going back up any time soon I'm afraid. I just don't
have the time to work on it any more. If I do find the time, I'll be
sure to let you know.
King Regards,
Dave) 。 )
这个。。。看来使用lucene还是比较重量啊。
4. sphinx . 貌似是LUCENE 的竞争者。 sphinx 基本等同于 lucene + solr. sphinx 不但有lucene的功能,而且也提供了一个SERVER。 对MYSQL, POSTGRES集成的非常好,还有自身的 sphinx QL. 不过由于我用的是 mongo ,所以。。。
5. 不过,sphinx 在RAILS3中有工具:
thinking sphinx, 非常详细的文档。github上的关注度超过了1K, 而且最下面有很长的作者列表,粗略估算一下,估计有180人。看来就是它了。。。重点的candidate.
6. 非常棒!找到了中文分词库:
http://www.sphinx-search.com/ sphinx-for-chinese是一款专注于中文搜索的全文检索软件,在sphinx的基础上添加了中文处理模块并优化了中文搜索效果。
7. 其他选项:
ravendb ,内置支持了lucene。是开源的,不过也有商用版本。 用C# 写的。
GITHUB 关注度 700+ 不考虑了。。。
8. mongoid plugin:
mongoid_fulltext 上手非常快,文档看起来不错。可惜分词不支持中文。。。 只是很简单的 几个选项(用空格隔开,等等)
mongoid_search, 也是对mongoid的支持。可惜不支持中文。。。
分享到:
相关推荐
InspiniaAdmin 2.6.1 Rails_Full_Version
inspinia admin 2.5 中的 Rails_Full_Version
Ruby+on+Rails+3+Tutorial.pdf 应用Rails进行敏捷Web开发第4版.pdf (Agile Web Development with Rails) Rails.Recipes.Rails.3.Edition.pdf
Rails3教程系列 DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY(Dont Repeat Yourself) DRY...
inspinia admin Rails全版本 购买版本
InspiniaAdmin 2.5 Rails_full_version
rails2和rails3版本的改动区别。
Rails 3 in Action 2011年9月新鲜出炉,针对最新的Rails 3.1进行说明
Bootstrap 3 和 Rails 4(样例用的是Ruby 2.1.1,Rails 4.1.4) Table of Contents Preface 1 Chapter 1: Introducing Web Application Development in Rails 7 Why Bootstrap with Rails? 8 Setting up a Todo ...
rails3的英文文档
Rails3消息队列系统 Sidekiq
Windows7_Cygwin_Git_RVM_Ruby1.9.3_Rails3_MongoD B_Nginx_Unicorn_Rspec_Guard_Spork(2-Ruby on Rails3 安装配置
rails常用命令,例如新建rails项目,新建controller、model 等等
Rails3的ActiveRecord 查询API.doc
turbo-sprockets-rails3, 加速你的Rails 3资产 用于 Rails 3.2.x的涡轮链轮 通过只根据源文件的哈希来重新编译已经更改的资产,从而加快 Rails 3 rake assets:precompile的速度只编译一次以生成指纹和非打印的资产...
Rails进行敏捷Web开发(所有版本的源码rails3.0-4.0) 3.0,3.1,3.2,4.0
ruby on rails开发的初学者很适合的工具书,易上手,很实用,
The Rails™ 3 Way is a comprehensive resource that digs into the new features in Rails 3 and perhaps more importantly, the rationale behind them. —Yehuda Katz, Rails Core The Bible for Ruby on ...