Thinking Sphinx - complicated sort on two fields
I am using thinking sph开发者_如何学Goinx for search. Now I need to order my search results by two fields.
The complicated part starts with this:"if date_approved is not null use it, else use created_at date for sorting the results in descending order"
I implement this without thinking sphinx as :
@model_values=Model.find(:all,
:conditions => {:name => :johndoe},
:select => "*,if(date_approved,date_approved,created_at) as my_date",
:order => 'my_date DESC')
But when I come to thinking_sphinx, I am stumped.
Any help is appreciated. ThanksOn the SQL side, you're probably looking for ROR to produce
ORDER BY COALESCE(date_approved, created_at) DESC
COALESCE() returns the first argument that's not NULL.
精彩评论