複数のフィールドでSunspot/Solrを使用する方法はありますか?このスクリーンキャストで説明したように それは、単純な形式で正常に動作します:Sunspot/Solr:複数のフィールドで検索する
product.rb
searchable do
text :address
text :model
text :category
end
* products_controller:http://railscasts.com/episodes/278-search-with-sunspot
あなたは動作しません、私の案を見ることができます。 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'
みんなありがとう!場合
ありがとう、私はこのようにします。 – remjih
これは@reminkが ':model'と':category'でクエリをスコープすることを要求していたものではありません。 – thekingoftruth