正在考虑 Sphinx 分面搜索实施示例?
我正在整理一个存储库类型的 Rails 3 站点。 我已经安装了 Thinking Sphinx 并在我的网站上运行,因为我可以输入像 localhost:3000/articles?search=test&page=2
这样的网址,它将返回预期的结果。
我是 Rails 新手(以及一般的 Web 开发人员);我认为我可以管理模型和控制器方面的问题,但到目前为止的观点让我感到困惑。我有一个侧边栏,我想用作搜索界面。我最接近的是这个(作为侧边栏部分的一部分呈现):
<% form_tag @search, :method => :get do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search"%>
<% end %>
搜索方法位于我的articles#index控制器中,当我在浏览器指向该页面时测试它(路由为/articles< /code>),它按预期工作,但有这个奇怪的网址:
localhost:3000/articles?utf8=✓&search=test&commit=Search
。当浏览器第一次指向根路径时,什么也没有发生。
所以,我认为这些是我需要解决的主要问题:
- 编辑 - 已解决(见下文)
- 我应该将搜索方法移至它们自己的控制器,还是应该将它们作为文章控制器的一部分?目前,Article 将是唯一被索引的模型。
- 编辑 - 已解决(见下文)
- 有谁有使用 Rails 3 和 Thinking Sphinx 的分面搜索视图的任何好的示例代码吗?就像我说的,我是一个新手,对浏览视图实现的文档感到有点慌张。然而,只要代码相当完整,我就相当擅长阅读和解释代码。
提前致谢!
已解决:
如何让“搜索”按钮在尝试搜索之前调用索引方法? (我已经通过用
articles_path
替换@search
解决了这个问题)。使用
will_paginate
解决了,我以前遇到过麻烦,但现在似乎可以工作。
I am putting together a repository-type rails 3 site.
I have Thinking Sphinx installed and working on my site, insomuch as I can enter urls like localhost:3000/articles?search=test&page=2
and it will return the expected results.
I'm new to Rails (and web dev in general); I think I can manage the model and controller aspects of this, but the views so far have me stumped. I have a sidebar I would like to use as the search interface. The closest I have come is this (rendered as part of a sidebar partial):
<% form_tag @search, :method => :get do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search"%>
<% end %>
The search method is in my articles#index controller, and when I test it when the browser is pointed to that page (routed as /articles
), it works as expected, but with this odd url: localhost:3000/articles?utf8=✓&search=test&commit=Search
. When the browser is first pointed to the root path, nothing happens.
So, I think these are the main issues I need to address:
- EDIT - solved (see below)
- Should I move the search methods to their own controller, or should they be part of the articles controller? For now, Article will be the only model indexed.
- EDIT - solved (see below)
- Does anyone have any good example code of a faceted search view using Rails 3 and Thinking Sphinx? Like I said, I am something of a neophyte and am a little flustered by the documentation that skims by the view implementation. However, I am fairly adept at reading and interpreting code as long as it is reasonably complete.
Thanks in advance!
Solved:
How do I make the 'Search' button call the index method before trying to search? (I have solved this by replacing
@search
witharticles_path
).Solved using
will_paginate
, which I had trouble with before, but which seems to be working now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿,
这是我切换到 solr 之前我的网站如何工作的摘录
产品有很多类别,我们告诉 sphinx 我们希望将它们索引为构面
结果控制器
然后在视图中您可以执行类似的操作
Hey,
This is an extract of how my site worked before i switched to solr
Product has many categories, we tell sphinx that we want to index them as facets
Results Controller
And then in the view you can do something like