Hi Ryan

A couple of things to note… firstly, Sphinx stores integers as unsigned values 
- so negative values aren't handled as you'd hope. It may be worth switching to 
floats instead for those attributes? Also, Sphinx doesn't have a concept of 
NULL - they're stored as zeros, so you may want to change your IF logic to 
match:

  IF(val1 = 0, val2, val1)

Though perhaps Sphinx treats zeros as false, and it's just the unsigned issue 
that's causing problems. Adding :type => :float to the attribute definitions 
should ensure the types are handled appropriately. If that doesn't help, let me 
know.

Cheers

-- 
Pat

On 27/08/2012, at 6:58 PM, Ryan LeCompte wrote:

> Hello,
> 
> I'm trying to use Thinking Sphinx on a Ruby project to order search results. 
> I'm using the advanced search expression functionality, however it's not 
> behaving as expected.
> 
> I'm basically doing the following:
> 
> search_options = {:sort_mode => :expr, :order => "IF(val1, val1, val2)"}
> 
> My goal is to order this by val1 if val1 is present, otherwise order by val2.
> 
> When I execute this, I see things that have a val1 of -1 getting put before 
> things that have a positive val2 value.
> 
> Here's an example search result:
> 
> val2: [3, 999, 190, 13, 9, 6, 6, 4, 4, 4, 3, 3, 2, 2, 2, 2, 2, 2, 2]
> val1: [-1, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 
> nil, nil, nil, nil, nil]
> 
> I'm seeing the object with a val1 of -1 coming first, then the object with a 
> val2 of 999, then 190, then 13, etc.
> 
> So, is there a reason why Thinking Sphinx is forcing the object with a val1 
> of -1 to the top? Is there an easy way to fix this?
> 
> Thanks!
> 
> Ryan
> 
> -- 
> 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/-/_8DSj-CL-KQJ.
> 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 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