2013-01-11 92 views
8

我有以下我stories.rb模型pg_search范围:如何去除查询结果排名

pg_search_scope :with_text, 
        :against => :title, 
        :using => { :tsearch => { :dictionary => "english" }}, 
        :associated_against => { :posts => :contents } 

我想查询返回的结果忽略任何排名(我只在乎日期故事最近更新了命令DESC)。我知道对于大多数查看它的人来说这是一个简单的问题,但是如何关闭pg_search中的排序顺序?

回答

22

我是pg_search的作者。

你可以做这样的事情,它采用ActiveRecord::QueryMethods#reorder

MyModel.with_text("foo").reorder("updated_at DESC") 
+3

优秀。谢谢!顺便说一句,不需要'.reorder.order(“updated_at DESC”)'。只需要'.reorder(“updated_at DESC”)' –

+0

很酷!更新了我的答案。 – nertzy

+0

谢谢,这对我也很有用。任何方式来使用published_at字段?问题在这里:http://stackoverflow.com/questions/21604862/pg-search-how-to-order-by-published-at-field-in-multisearchable – Ben