Last active
February 6, 2021 02:30
-
-
Save montanalow/86d5cc200076a8e4ffec1b1c86a02703 to your computer and use it in GitHub Desktop.
Rank full text search results with weighted scores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM products | |
NATURAL JOIN search_product_conversions | |
NATURAL JOIN items | |
WHERE items.keywords @@ ts_query('fuji | apple') | |
AND items.retailer_location_id = 123 | |
AND search_products_conversions.query = 'fuji apple' | |
ORDER BY | |
(100 * search_product_conversions.count) + | |
( 10 * products.popularty) + | |
( 1 * ts_rank(items.keywords, ts_query('fuji | apple'))) | |
DESC | |
LIMIT 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment