环境:RoR 3.2 + Postgres
我创建了一个services
具有 2 个文本属性的表:title
和description
我要操作以下全文搜索:
SELECT * FROM (
SELECT DISTINCT ON (s.id) s.*,
ts_rank_cd(s.service_tsv, query) AS rank
FROM to_tsquery('red | drawing | fun') AS query,
services AS s
WHERE (s.service_tsv @@ query)
ORDER BY s.id DESC
) AS sub ORDER BY rank DESC;
SQL 语句就像一个魅力,但我如何将其转换为 Rails ORM:
Service.joins(???).where(???).uniq