2014-03-13 32 views

回答

0

YEAR函數可以滿足您的需求,但值得注意的是您需要在SELECT子句中使用它,給結果一個別名,然後在您的ORDER子句中引用該別名。

這是假設你正在使用TS V3:

Model.search 'foo', 
    :select => '*, YEAR(created_at) as created_at_year, weight() as weight', 
    :order => 'created_at_year DESC, weight DESC' 
+0

TS v2的任何解決方案?由於該項目依賴於Rails 3.0,因此無法更新。 –

+0

對於TS v2,嘗試將':select'更改爲':sphinx_select'。我認爲這應該是所有需要的。 – pat

0

工作代碼與獅身人面像在OSX思考獅身人面像V2 2.1.6

:sphinx_select => "*, YEAR(created_at) as created_at_year", :order => "created_at_year DESC, weight() DESC") 

代碼與獅身人面像在BSD思考獅身人面像V2 2.0.6

:sphinx_select => "*, YEAR(created_at) as created_at_year, weight() as my_weight", :order => "created_at_year DESC, my_weight DESC") # can't be aliased as weight! 
相關問題