So my Database is set up with a :bar, :day, :deal. Day is in the form of Monday, Tuesday...
I want to facet on :day, but no facets will show up. Does anything stick out that I have done wrong?
h_contoller
def index
@search = Happy.search do
fulltext params[:search]
facet(:day)
paginate :page => 1, :per_page => 550
end
@happies = Happy.where(id: @search.results.map(&:id)).page(params[:page])
end
model
searchable do
text :name, :boost => 5
text :day, :boost => 10
string :day
end
view
<% @search.facet(:day).rows.each do |facet| %>
<p><%= puts "Author #{facet.value} has #{facet.count} pizza posts!" %></p>
<% end %>
In your Model You have the field day defined twice:
text :day, :boost => 10
string :day
Facets should be applied on string not text. You just need to rename one of the field in your model :
text :day, :boost => 10
string :day_str do
day
end
end then do the facet on it :
def index
@search = Happy.search do
fulltext params[:search]
facet(:day_str)
paginate :page => 1, :per_page => 550
end
@happies = Happy.where(id: @search.results.map(&:id)).page(params[:page])
end
and in the view:
<% @search.facet(:day_str).rows.each do |facet| %>
<p><%= puts "Author #{facet.value} has #{facet.count} pizza posts!" %></p>
<% end %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.