ๆๅจhereไธๅไบไธไธช้ฎ้ข๏ผไฝๅๆฅๆๅ็ฐ่ชๅทฑๆณ่ฆ็ไธไป ไป ๆฏๆ็่ฆๆฑใ
ๆๅฎ้
ไธ้่ฆๅจname
ๅ็ๆ้ซts_rank
ไธ่ฟ่กDISTINCT๏ผๆไปฅๆ็ไปฃ็ ๆฏ๏ผ
SELECT name
,ts_rank(to_tsvector(name), query) + ts_rank(to_tsvector(content), query2) AS rank
FROM users
INNER JOIN microposts ON users.id = microposts.user_id
,plainto_tsquery('re') query
,plainto_tsquery('comics') query2
WHERE users.name @@ query
OR microposts.content @@ query2
ORDER BY rank DESC;
็ปๅบ
โโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโ
โ name โ content โ rank โ
โ โโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโฃ
โ Dawson Kreiger โ dc comics dc comics dc comics dc comics โ 0.0919062 โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโข
โ Kaylin Green โ dc comics dc comics dc comics โ 0.0889769 โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโข
โ Dawson Kreiger โ dc comics dc comics โ 0.0827456 โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโข
โ Kaylin Green โ dc comics โ 0.0759909 โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโข
โ Dawson Kreiger โ I went to the beach dc comics โ 0.0607927 โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโข
โ Dawson Kreiger โ I went to the beach dc comics โ 0.0607927 โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโข
โ Kaylin Green โ I went to the beach dc comics โ 0.0607927 โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโข
โ Kaylin Green โ I went to the beach dc comics โ 0.0607927 โ
โโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโ
ๆไปฅๆ้่ฆ่พๅบไธบๆญค๏ผ
โโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโคโโโโโโโโโโโโ
โ name โ content โ rank โ
โ โโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโฃ
โ Dawson Kreiger โ dc comics dc comics dc comics dc comics โ 0.0919062 โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโข
โ Kaylin Green โ dc comics dc comics dc comics โ 0.0889769 โ
โโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโงโโโโโโโโโโโโ
ๆไปฅๆ้่ฆ้ๆฉไธไธชๅ็งฐไธๅไธ่ฎฐๅฝๆ้ซrank
็่ฎฐๅฝใไฝๆฏไปฃ็ ๅฆไฝ็ฅ้ๅฆไฝ้ๆฉๅ
ทๆๆ้ซts_rank็็ฌ็น็จๆท๏ผ
ไฟฎๆน
ไพๅฆ๏ผๅฆๆๆ่ฟๆ ทๅ
SELECT name
, ts_rank(to_tsvector(name), query) + ts_rank(to_tsvector(content), query2) AS rank
FROM
(
SELECT DISTINCT name FROM users WHERE rank = MAX(rank)
)
INNER JOIN microposts ON users.id=microposts.user_id
, plainto_tsquery('re') query
,plainto_tsquery('comics') query2
WHERE users.name @@ query
OR microposts.content @@ query2
ORDER BY rank DESC;
ๆๅพๅฐerror: column "rank" does not exist
็ญๆก 0 :(ๅพๅ๏ผ1)
ๆจๅฏไปฅไฝฟ็จviewDidLoad
่ฟ่กGROUP BY
ใ
MAX