开发者

Sort thinking sphinx by attribute AND @random?

So I'd like to be able to sort first by an attribute, and then amongst those with the same attribute value, sort randomly.

As in:

{ :sort_mode => :extended, :order => "attribute DESC, @random ASC" }

In my case the attribute is boolean, so I just want the ones that are true to all display before the ones that are false, but for the order within each of the true and false buckets to be random.

For some reason, this does not return any results. If I modify the abov开发者_如何学编程e, and change @random to @relevance, it works:

{ :sort_mode => :extended, :order => "attribute DESC, @relevance ASC" }

Is there something wrong with using @random to sort along with other attributes? If so, is there a different solution to my problem??

Thanks!!


When you use @random (your first example), can you look at raw search results - there may be an error or warning that could explain more:

search = ThinkingSphinx.search(
  :sort_mode => :extended,
  :order     => 'attribute DESC, @random ASC'
)
search.results
search.results[:error]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜