Rails - 搜索控制器
我正准备在我的应用程序中构建搜索功能。我希望搜索能够跨越多个模型。
我正在考虑添加一个搜索控制器,然后它会根据设置等决定要搜索的模型......
您觉得怎么样?搜索控制器听起来正确吗?或者我应该考虑一些开源的东西吗?
谢谢
I'm getting ready to build search capabilities into my app. I want the search to have the ability to span multiple models.
I'm thinking about adding a search controller which would then decide which models to search based on settings etc...
What do you think? Does a search controller sound right or is there something open-source I should be thinking about?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 ruby 世界中,您有多种搜索选项,例如
浏览 Heroku 的文档,heroku 建议使用 solr,这是一个很棒的搜索引擎。 http://docs.heroku.com/websolr 和 http://docs.heroku.com/full-text-search 详细介绍了更多相关信息。我们在一个项目中选择 solr 进行搜索,并使用 sunspot_rails ,它可以很好地与您的模型集成,并在您的内容更改时重新索引。我们使用了 http://github.com/outoftime/sunspot 中的 gem sunspot_rails,这也是heroku推荐的。
但需要注意的是,heroku 的文件系统是只读的,不允许您运行任意进程,因此您必须选择像 websolr(每月 20 美元起)或生成您自己的 amazon ec2 实例并在那里建立索引。由于heroku也在亚马逊ec2上运行,因此延迟非常非常少。
回到替代方案,众所周知,Ferret 在生产中经常会崩溃/损坏索引。 Heroku 不支持 Sphinx。 Endeca 非常昂贵,你必须花费大部分预算才能获得基本结果。
You have a couple of options for search in ruby world like
Going through the documentation of heroku, heroku suggests with solr which is an awesome search engine. http://docs.heroku.com/websolr and http://docs.heroku.com/full-text-search details more information about that. We chose solr for search in one of our projects and we used sunspot_rails which nicely integrates with your models and reindexes when your content changes. We used the gem sunspot_rails from http://github.com/outoftime/sunspot which is recommended by heroku too.
Caveat though is that heroku's file system is read only and does not allow you to run arbitrary processes, so you have to choose one like websolr(starts from 20$ a month) or spawning your own amazon ec2 instance and do the indexing there. Since heroku is also running on amazon ec2, the latency is very very less.
Getting back to the alternatives, Ferret is known to crash/corrupt indexes often in production. Sphinx is not supported by heroku. Endeca is damn expensive, you gotta spend most of your budget just even to get basic results.
如果您使用 Postgres,则可以使用 pg_search gem
If you are using Postgres, you can use the pg_search gem
我想说避免滚动你自己的搜索“引擎”,除非你有一个非常具体的需求,无法通过诸如 Sphinx(另请阅读此)
I would say avoid rolling your own search "engine" unless you have a very specific need that cannot be met by something like Sphinx (also read this)