Search code examples
ruby-on-railsrubyelasticsearchsearchkickvote

Ordering Searchkick's search result by act_as_votable vote score


I'm using act as votable for voting on my rails app and searchkick for search. But i want searchkick's search results to be order by vote score. I really need guys, please anybody? Here is what I have at the moment. And it's not working

def search

 if params[:search].present?
   @peegins = Peegin.search(params[:search]).order(:cached_votes_score => :desc)

 else
   redirect_to peegins_path
end

Solution

  • I finally figured it out. The problem was the bracket around the search params. Here's the fix.

    @peegins = Peegin.search params[:search], order: { cached_votes_score: :desc}