First, sorry for my bad english. I'm new to Ruby on rails. I used sunspot gem.
Using facet feature, when I got search result it appears like this {1=>2015, 2=>12, 3=>1} (2) {1=>2015, 2=>11, 3=>1} (1) {1=>2016, 2=>7, 3=>1} (1)
I want it to appear like this 2015/12 (2) 2015/11 (1) 2016/7 (1)
Below is the full method code: index.html.erb
<div id="facets">
<h3>Published</h3>
<ul>
<% for row in @search.facet(:month).rows %>
<li>
<% if params[:month].blank? %>
<%= link_to row.value, :month => row.value %> (<%= row.count %>)
<% else %>
<strong><%= row.value %></strong> (<%= link_to "remove", :month => nil %>)
<% end %>
</li>
<% end %>
</ul>
</div>
trip.rb
searchable do
text :destination
string :month
end
trips_controller.rb
def index
@search = Trip.search do
fulltext params[:search]
with(:month).greater_than_or_equal_to(Time.zone.now)
facet(:month)
with(:month, params[:month]) if params[:month].present?
end
@trips = @search.results
#trips = Trip.where(@filters)
#@languages = Trip.pluck(:language).uniq
#@interests = Trip.pluck(:interests).uniq
#@destinations = Trip.pluck(:destination).uniq
end
Aucun commentaire:
Enregistrer un commentaire