11

I have the following pg_search scope on my stories.rb model:

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

I want the query to return the results ignoring any ranking (I care only about the date the story was last updated order DESC). I know that this is an easy question for most of the people who view it, but how do I turn off the rank ordering in pg_search?

chuck w
  • 1,741
  • 2
  • 15
  • 34

1 Answers1

30

I'm the author of pg_search.

You could do something like this, which uses ActiveRecord::QueryMethods#reorder

MyModel.with_text("foo").reorder("updated_at DESC")
Seth
  • 10,198
  • 10
  • 45
  • 68
Grant Hutchins
  • 4,275
  • 1
  • 27
  • 32
  • 3
    Excellent. Thanks! BTW, didn't need `.reorder.order("updated_at DESC")`. Only needed `.reorder("updated_at DESC")` – chuck w Jan 16 '13 at 23:27
  • Thanks, this was really useful for me too. Any way to use a published_at field instead? Question here: http://stackoverflow.com/questions/21604862/pg-search-how-to-order-by-published-at-field-in-multisearchable – Space Feb 06 '14 at 13:54