Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
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