Grouping search results with thinking_sphinx plugin for rails

Posted by Shagymoe on Stack Overflow See other posts from Stack Overflow or by Shagymoe
Published on 2010-03-15T14:45:52Z Indexed on 2010/03/15 14:49 UTC
Read the original article Hit count: 287

I can use the following to group results, but it only returns one result per group.

    @results = Model.search params[:search_query], 
                            :group_by => 'created_at',
                            :group_function => :day,
                            :page => params[:page],
                            :per_page => 50         

So, if I display the results by day, I only get one result per day.

<% @results.each_with_groupby do |result, group|  %>
  <div class="group"><%= group %></div>    
  <ul class="result">
    <li><%= result.name %></li>
  </ul>
<% end %>

Do I have to parse the @results array and group them by date manually or am I missing something? Here is the line from the sphinx docs: http://sphinxsearch.com/docs/current.html#clustering

"The final search result set then contains one best match per group."

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about thinking-sphinx