Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

undergroundwebdesigns
Copy link

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 undergroundwebdesigns changed the title Add option to disable ranking of results entirely. Add option to disable ranking of results entirely when using pg_search_scope. Aug 17, 2015
@shan98
Copy link

shan98 commented Jan 29, 2016

+1

@jeffcarbs
Copy link

+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.

@tamaloa
Copy link

tamaloa commented Mar 21, 2017

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

@iwz
Copy link

iwz commented May 2, 2019

Hi, @nertzy!

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

@nertzy
Copy link
Collaborator

nertzy commented May 11, 2019

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.

@futuretap
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants