使用 Websolr 和 Heroku 进行全文搜索
您好,我在尝试弄清楚如何在我的应用程序中全局实现搜索表单时遇到困难。我有一系列帖子需要由登录和未登录的用户搜索。我已在我的帖子模型中添加了以下代码:
searchable do
text :content, :default_boost => 2
text :body, :default_boost => 1.5
end
但是,我不知道从哪里开始创建跨所有帖子的搜索字段页面并使其显示我需要的结果。我是 Rails 新手,如果有人愿意帮助我,我很乐意发布更多信息。
Hi I am having trouble trying to figure out how to implement a search form globally across my application. I have a series of posts that need to be searchable by users that are signed in and not signed in. I have added this code in my post model:
searchable do
text :content, :default_boost => 2
text :body, :default_boost => 1.5
end
However, I do not know where to go from there to create a search field across all pages and make it show the results I need. I am new to rails and would be happy to post more information if someone is willing to help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您应该按照以下railscast中的说明添加搜索字段: http://railscasts.com /episodes/37-simple-search-form
由于您的搜索并不特定于特定模型,因此请使用通用控制器名称而不是 ProjectsController。
然后,您应该使用 Sunspot DSL 来替换 ActiveRecord finder。
以下是帮助您入门的示例代码:
在您看来,您可以遍历 @search.results
最后,使用 WebSolR 而不是标准 SolR 服务器非常简单,
您可以按照 https://github.com/onemorecloud/websolr-rails。编辑:
正如 Nick 评论的那样,您完全应该访问 http://docs.heroku.com/websolr。
谢谢尼克!
First, you should add your search field like explained in this railscast: http://railscasts.com/episodes/37-simple-search-form
Since your search isn't specific to a particular model, use a generic controller name instead of ProjectsController though.
Then, you should replace the ActiveRecord finder by the use of the Sunspot DSL.
Here is an sample code to help get you started:
In your view, you can then iterate through @search.results
Last, using WebSolR instead of a standard SolR server is quite simple,
you can follow the setup instructions at https://github.com/onemorecloud/websolr-rails.Edit:
As Nick commented, you should totally go to http://docs.heroku.com/websolr.
Thanks Nick !