开发者

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.

Thanks


On 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜