Sunspot Rails - 用户可以更改要搜索的字段吗?
我开始使用 Sunspot 在 Rails 3 应用程序中执行搜索,但遇到了疑问。有没有一种方法可以让用户选择他/她想要搜索的字段。例如,在我的应用程序中,我们有:
class Project < ActiveRecord::Base
searchable do
text :name, :content, :keyword
end
end
在视图中默认搜索栏:
<%= form_tag projects_path, :method => :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
我可以添加单选按钮或类似的东西,以便用户可以标记它以便仅按名称、内容或关键字进行搜索吗?如果是的话,我该怎么做?
多谢。
I started using Sunspot to perform searches in my Rails 3 app and I ran into a doubt. Is there a way that I can let the user choose in what fields he/she wants to search. For example, in my app we have:
class Project < ActiveRecord::Base
searchable do
text :name, :content, :keyword
end
end
And in the View the default search bar:
<%= form_tag projects_path, :method => :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
Can I add a radio button or something like that so the user can mark it in order just to search by name, or content or keyword? If yes, how can I make it?
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
观看有关该主题的 Railscast:http://railscasts.com/episodes/278-search- with-sunspot .. 在其中,Ryan 让用户可以选择按月份进行查询。
因此,如果发送了月份:
Watch the railscasts on the subject: http://railscasts.com/episodes/278-search-with-sunspot .. in it, Ryan lets user's query optionally by month.
So, if month was sent in: