使用 sunspot/solr 搜索表单

发布于 2024-12-06 19:17:14 字数 913 浏览 4 评论 0原文

我是第一次使用太阳黑子,我正在尝试设置搜索。全文搜索似乎工作正常。但是,我有一个带有搜索框和用户可以选择的布尔字段上的多个过滤器的表单。不知何故,搜索框工作正常,但 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如荒岛 2024-12-13 19:17:15

变量命名有错误。

There was an error in variable naming.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文