@random order

142 views
Skip to first unread message

Abdo Achkar

unread,
Jun 29, 2012, 9:07:54 AM6/29/12
to thinkin...@googlegroups.com
Hello :-)

I'm attempting to return results ordered by "has_images" first, and then @random.

I tried the following syntaxes:

:order => "has_images DESC, @random"
:order => "has_images DESC, @random DESC"
:order => "@random + ( has_images * 1000000.0 ) DESC"

The first two syntaxes give Sphinx Daemon returned error: index location_core,location_delta: sort-by attribute '@random' not found
and the third syntax causes the whole set to be sorted randomly

Note that :order => "has_images DESC" works.

Is this something that Sphinx can't do or am I missing something?

Best regards,
A

Pat Allan

unread,
Jun 29, 2012, 9:18:35 AM6/29/12
to thinkin...@googlegroups.com
I think it's a limit in Sphinx itself - you can sort by @random, *OR* by attributes etc, but @random can only be used by itself.
http://stackoverflow.com/questions/6466657/randomize-search-result-in-sphinx

Cheers

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/WNL5ZuCJaP0J.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.



Abdo Achkar

unread,
Jun 29, 2012, 11:07:53 AM6/29/12
to thinkin...@googlegroups.com
Pat, I really appreciate your constant support!

I found a way around it using a little hack:

I indexed the ids of my table, and sorted by expr.

My expression looks like this (I'm still messing around with it)
expr = has_images  * abs (  sin( #{Math::PI / pagesize} * ( id % #{pagesize} + #{rand(pagesize)} ) ) )

The idea is to get the index of a sector in a semi circle, add a random number, then compute the sine...
Hopefully this won't end up being too inefficient or else I will have to cache =)

Best,
A

On Friday, June 29, 2012 4:18:35 PM UTC+3, Pat Allan wrote:
I think it's a limit in Sphinx itself - you can sort by @random, *OR* by attributes etc, but @random can only be used by itself.
http://stackoverflow.com/questions/6466657/randomize-search-result-in-sphinx

Cheers

--
Pat

On 29/06/2012, at 2:07 PM, Abdo Achkar wrote:

> Hello :-)
>
> I'm attempting to return results ordered by "has_images" first, and then @random.
>
> I tried the following syntaxes:
>
> :order => "has_images DESC, @random"
> :order => "has_images DESC, @random DESC"
> :order => "@random + ( has_images * 1000000.0 ) DESC"
>
> The first two syntaxes give Sphinx Daemon returned error: index location_core,location_delta: sort-by attribute '@random' not found
> and the third syntax causes the whole set to be sorted randomly
>
> Note that :order => "has_images DESC" works.
>
> Is this something that Sphinx can't do or am I missing something?
>
> Best regards,
> A
>
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/WNL5ZuCJaP0J.

> To post to this group, send email to thinking-sphinx@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphinx+unsubscribe@googlegroups.com.

Abdo Achkar

unread,
Jun 29, 2012, 11:23:03 AM6/29/12
to thinkin...@googlegroups.com
A simpler way... Not sure if it's completely random though.

(  ( ( id % #{pagesize} + #{rand(pagesize * 2)} ) % #{pagesize} ) / #{pagesize} )
Reply all
Reply to author
Forward
0 new messages