How to remove ranking of query results
Asked Answered
M

1

12

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?

Mccauley answered 11/1, 2013 at 20:34 Comment(0)
A
31

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")
Aloft answered 14/1, 2013 at 3:24 Comment(2)
Excellent. Thanks! BTW, didn't need .reorder.order("updated_at DESC"). Only needed .reorder("updated_at DESC")Mccauley
Thanks, this was really useful for me too. Any way to use a published_at field instead? Question here: #21605362Roister

© 2022 - 2024 — McMap. All rights reserved.