0

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 above, 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!!

Mat
  • 202,337
  • 40
  • 393
  • 406
Steven Ou
  • 393
  • 2
  • 13

1 Answers1

0

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]
pat
  • 16,116
  • 5
  • 40
  • 46
  • that shows: index service_core,service_delta: sort-by attribute '@random' not found – Steven Ou Dec 09 '10 at 02:09
  • What version of Sphinx are you using? – pat Dec 11 '10 at 13:56
  • 0.9.9. actually i read somewhere that it's a limitation of sphinx: can't sort by @random and another attribute. but it was also a post in 2008, and it said they were working on fixing the issue? maybe it works on 1.10-beta? but from my understanding thinking sphinx's support for the beta isn't too good? – Steven Ou Dec 13 '10 at 06:19