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 ranking order to set higher priorities over rank #513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

keymastervn
Copy link

This PR changes how the gem is ranked by default pg_search.rank DESC, followed up by order_within_rank as the tiebreaker. Now, it supports ordering by other fields BEFORE pg_search.rank

In my case, ranking is not the most important to be considered first. For instance, we have options to sort by relevance order (1) AND posted date order (2). The requirement for (2) will respect the posted date order before another matching, similar to partitioning by date and apply ranking inside the partitions.

This option ranking_order somehow is opposite to order_within_rank, please suggest me a proper name.

@futuretap
Copy link

I need to order using a custom distance function, so this unfortunately isn't flexible enough.
However, I found I can simply use reorder to get rid of the pg_search ranking order and use my own order.

@keymastervn
Copy link
Author

@futuretap I am still unclear on what your use case is, can you please provide me more context, perhaps a SQL query?
The option ranking order may come with a hash or string. If your distance is the below distance_meters

SELECT earth_distance(
  ll_to_earth(37.77492, -122.41942),
  ll_to_earth(40.71278, -74.00595)
) AS distance_meters

Then the option is simply ranking_order: "distance_meters DESC".

In my case, I want to count the tsvector weight as well, so your change reorder must have a way to count #{rank_table_alias}.rank as well if I don't get wrong.

@futuretap
Copy link

My order is using PostGIS: location <-> 'SRID=4326;POINT(11.0 48.0)'::Geometry and I don't want to use the search rank at all.

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

2 participants