简体   繁体   中英

Grouping search results with thinking_sphinx plugin for rails

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."

Here's similar documentation for thinking_sphinx:

http://freelancing-god.github.com/ts/en/searching.html#grouping

Unfortunately, I'm not sure I understand your question enough to give you a better answer at the moment. Care to clarify?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM