pg_search icon indicating copy to clipboard operation
pg_search copied to clipboard

Add option to disable ranking of results entirely when using pg_search_scope.

Open undergroundwebdesigns opened this issue 9 years ago • 6 comments

This PR adds the option to set ignoring = :rank, which will cause pg_search to skip ordering the search results entirely, and to remove all calls to ts_rank from the query.

This change allows for much faster queries where ranking isn't important, especially where the search terms may match thousands of documents.

undergroundwebdesigns avatar Aug 17 '15 16:08 undergroundwebdesigns

+1

shan98 avatar Jan 29 '16 20:01 shan98

+1 :+1:

I'm currently searching on a large table where the user chooses their own order, so the rank doesn't matter. I'm getting around this issue by clobbering the order via relation.reorder(:my_order) but reading this PR made me realize the DB is still calculating the rank.

jeffcarbs avatar Feb 13 '16 05:02 jeffcarbs

+1 We have been using this pull request in production for some time now and would really like to see it merged into master.

tamaloa avatar Mar 21 '17 16:03 tamaloa

Hi, @nertzy!

Looks like this has already been merged. I think this can be closed.

iwz avatar May 02 '19 21:05 iwz

Hi, @iwz!

I looked closer and I don't think there is a way to completely turn off ordering. It may be possible to do something like this, using except:

MyModel.my_search("my query").except(:order)

But I haven't tried it.

I'd consider merging this pull request if it is rebased and conflicts are fixed. I'd also want to change the API from ignoring: :rank to ranked_by: nil or ranked: false or something similar, because we already use ignoring: to trigger processing of the search query and document. I don't want the same key to also affect scope options.

nertzy avatar May 11 '19 18:05 nertzy

Even though it was merged, it has been overwritten and the option is no longer available. I resorted to use reorder to modify the ordering after the fact.

futuretap avatar Jul 21 '23 07:07 futuretap