使用 sunspot/solr 搜索表单
我是第一次使用太阳黑子,我正在尝试设置搜索。全文搜索似乎工作正常。但是,我有一个带有搜索框和用户可以选择的布尔字段上的多个过滤器的表单。不知何故,搜索框工作正常,但 solr 没有选择单个布尔值作为附加过滤器。另外,当我不执行任何搜索文本而只想按布尔字段搜索时,什么也没有发生。任何帮助将不胜感激:
这是我的控制器:
@search = Project.search do
fulltext params[:search]
facet(:master_bedroom)
facet(:dining_room)
facet(:bath)
with(:master_bedroom, params[:mb]) if params[:mb].present?
with(:dining_room, params[:dr]) if params[:dr].present?
with(:bath, params[:p_bath]) if params[:p_bath].present?
end
我在模型中有字段:
searchable do
text :description
boolean :dining_room
boolean :bath
boolean :master_bedroom
end
并且我的观点如下:
<%= form_tag projects_path, :method => :get do %>
<%= text_field_tag :search, params[:search] %>
<%= check_box_tag :bath, 'true'%>
<%= submit_tag "Search", :name => nil %>
<% end %>
I'm using sunspot for the first time and i'm trying to setup the search. full text search seems to work fine. however, i have a form with a search box and multiple filters on boolean fields that the user can select. somehow the search box works fine but solr isn't picking up the individual booleans as additional filters. also, when i don't do any search text and just want to search by the boolean fields, nothing happens. any help would be appreciated:
this is my controller:
@search = Project.search do
fulltext params[:search]
facet(:master_bedroom)
facet(:dining_room)
facet(:bath)
with(:master_bedroom, params[:mb]) if params[:mb].present?
with(:dining_room, params[:dr]) if params[:dr].present?
with(:bath, params[:p_bath]) if params[:p_bath].present?
end
i have the fields in the model:
searchable do
text :description
boolean :dining_room
boolean :bath
boolean :master_bedroom
end
and i have the following for my view:
<%= form_tag projects_path, :method => :get do %>
<%= text_field_tag :search, params[:search] %>
<%= check_box_tag :bath, 'true'%>
<%= submit_tag "Search", :name => nil %>
<% end %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
变量命名有错误。
There was an error in variable naming.