开发者

Grouping search results with thinking_sphinx plugin for rails

开发者 https://www.devze.com 2022-12-23 13:06 出处:网络
I can use the following to group results, but it only returns one result per group. @results = Model.search params[:search_query],

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>开发者_JS百科;
  </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?

0

精彩评论

暂无评论...
验证码 换一张
取 消