gpt4 book ai didi

ruby-on-rails - 太阳黑子/Solr : Searching with multiple fields

转载 作者:数据小太阳 更新时间:2023-10-29 08:05:45 25 4
gpt4 key购买 nike

在多个字段中使用 Sunspot/Solr 的方法是什么?它可以很好地处理一个简单的表单,如这个截屏视频中所解释的:http://railscasts.com/episodes/278-search-with-sunspot

你可以看到我的草稿不起作用:

product.rb

searchable do
text :address
text :model
text :category
end

*products_controller.rb*

  def search
@search = Sunspot.search(Product) do
fulltext params[:address]
with(:model, params[:model]) if params[:model].present?
with(:category, params[:category]) if params[:category].present?
end
@products = @search.results
end

products/search.html.erb

  <%= form_tag products_search_path, :method => :get do %>
<div class="field">
<%= label_tag "Address ?" %>
<%= select_tag :address, "<option>he</option><option>ho</option>".html_safe %>
</div>
<div class="field">
<%= label_tag "Model ?" %>
<%= text_field_tag :model, params[:model] %>
<%#= select_tag :model, "<option>hi</option><option>ha</option>".html_safe %>
</div>
<div class="field">
<%= label_tag "Category ?" %>
<%= text_field_tag :category, params[:category] %>
</div>
<div id="buttonSearch"><%= submit_tag "Search" %></div>
<% end %>

错误:

Sunspot::UnrecognizedFieldError (No field configured for Product with name 'model'):
app/controllers/products_controller.rb:99:in `block in search'
app/controllers/products_controller.rb:97:in `search'

感谢大家的帮助!

最佳答案

你只想要这个(下面)......你只想要全文,它将搜索你在可搜索中定义的所有字段......我使用“s”作为参数名称

@search = Sunspot.search(Product) do
fulltext(params[:s])
end

关于ruby-on-rails - 太阳黑子/Solr : Searching with multiple fields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7947647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com