Skip to content

Instantly share code, notes, and snippets.

@osiro
Created May 22, 2014 07:40
Show Gist options
  • Save osiro/17464a9c35a043863237 to your computer and use it in GitHub Desktop.
Save osiro/17464a9c35a043863237 to your computer and use it in GitHub Desktop.
SELECT
"projects".*,
((
ts_rank(
(
to_tsvector('english', coalesce("projects"."title"::text, '')) ||
to_tsvector('english', coalesce("projects"."description"::text, ''))
),
(
to_tsquery('english', ''' ' || 'qui' || ' ''')), 0)
)) AS pg_search_rank
FROM
"projects"
WHERE
((
(
to_tsvector('english', coalesce("projects"."title"::text, '')) ||
to_tsvector('english', coalesce("projects"."description"::text, ''))
) @@ (to_tsquery('english', ''' ' || 'qui' || ' '''))
))
ORDER BY pg_search_rank DESC, "projects"."id" ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment