pg_search
pg_search copied to clipboard
Add option to disable ranking of results entirely when using pg_search_scope.
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.
+1
+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.
+1 We have been using this pull request in production for some time now and would really like to see it merged into master.
Hi, @nertzy!
Looks like this has already been merged. I think this can be closed.
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.
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.