Sunspot でファセット検索を実装しようとしていますが、何か間違っているに違いありません。
class Product < ActiveRecord::Base
attr_accessible :category, :color, :condition, :item_no, :size
searchable do
text :color, :size
end
end
これは私の製品モデルです。ナビゲーションの横に、カテゴリ、色、状態などを使用して結果をフィルタリングできるメニューが必要です。
私のコントローラーには次のものがあります:
def index
@search = Product.search do
fulltext params[:search]
facet :color
end
@products = @search.results
respond_to do |format|
format.html
format.json { render json: @products }
end
end
しかし、次のようなエラーが表示され続けます。
Sunspot::UnrecognizedFieldError
No field configured for Product with name 'color'
私が持っているビューで:
<div id="facets">
<h3>Category</h3>
<ul>
<% for row in @search.facet(:color).rows %>
<li>
<% if params[:color].blank? %>
<%= link_to row.value, :color => row.value %> (<%= row.count %>)
<% else %>
<strong><%= row.value %></strong> (<%= link_to "remove", :color => nil %>)
<% end %>
</li>
<% end %>
</ul>
</div>
誰かが私が間違っていることを指摘できますか?
助けてくれてありがとう!
更新: これはエラーのトレースの一部です。
sunspot (1.3.3) lib/sunspot/query/restriction.rb:245:in `to_solr_conditional'
sunspot (1.3.3) lib/sunspot/query/restriction.rb:92:in `to_positive_boolean_phrase'
sunspot (1.3.3) lib/sunspot/query/restriction.rb:72:in `to_boolean_phrase'
sunspot (1.3.3) lib/sunspot/query/filter.rb:11:in `to_filter_query'
sunspot (1.3.3) lib/sunspot/query/scope.rb:5:in `block in to_params'
sunspot (1.3.3) lib/sunspot/query/scope.rb:5:in `map'
sunspot (1.3.3) lib/sunspot/query/scope.rb:5:in `to_params'
sunspot (1.3.3) lib/sunspot/query/common_query.rb:51:in `block in to_params'
sunspot (1.3.3) lib/sunspot/query/common_query.rb:50:in `each'
sunspot (1.3.3) lib/sunspot/query/common_query.rb:50:in `to_params'
sunspot (1.3.3) lib/sunspot/search/abstract_search.rb:37:in `execute'
sunspot_rails (1.3.3) lib/sunspot/rails/searchable.rb:329:in `solr_execute_search'
sunspot_rails (1.3.3) lib/sunspot/rails/searchable.rb:153:in `solr_search'