Как использовать 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
Продукты / 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'
Спасибо, ребята, за вашу помощь!