A simpler way... Not sure if it's completely random though.

(  ( ( id % #{pagesize} + #{rand(pagesize * 2)} ) % #{pagesize} ) / 
#{pagesize} )

On Friday, June 29, 2012 6:07:53 PM UTC+3, Abdo Achkar wrote:
>
> 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 [email protected].
>> > To unsubscribe from this group, send email to 
>> [email protected].
>> > For more options, visit this group at 
>> http://groups.google.com/group/thinking-sphinx?hl=en.
>>
>>
>>
>>

-- 
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/-/VASrNtoK8qEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to