Last active
December 20, 2019 14:42
-
-
Save thomas-mcdonald/0965b17f0df6e653558771570c56bb95 to your computer and use it in GitHub Desktop.
This file contains 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 | |
functions.id, | |
functions.slug, | |
ts_rank(setweight(to_tsvector('english', functions.name), 'A') || setweight(to_tsvector('english', coalesce(functions.search_docs,'')), 'B'), query) as rank | |
FROM ( | |
SELECT DISTINCT on (functions.slug) functions.* | |
FROM functions | |
INNER JOIN "klasses" ON "klasses"."id" = "functions"."klass_id" | |
INNER JOIN "versions" ON "versions"."id" = "klasses"."version_id" | |
ORDER BY functions.slug ASC, string_to_array(regexp_replace(versions.name, '[^0-9.]', '', 'g'), '.')::int[] DESC | |
) as functions, plainto_tsquery('test') query | |
ORDER BY rank desc | |
LIMIT 10 |
This file contains 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 "search_documents".* | |
FROM search_documents, plainto_tsquery('test') query | |
ORDER BY ts_rank(setweight(to_tsvector('english', search_documents.title), 'A') || setweight(to_tsvector('english', coalesce(search_documents.body,'')), 'B'), query) DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment