为什么我的 float 值总是为 postgres 查询中的所有条目返回 0?
How come my float value is always returning 0 for all entries in postgres query?
我一直想在我的网站中加入全文搜索,但搜索结果的排名 return 阻碍了我。 docs 展示了如何做到这一点,但我选择的所有 post 条目结果一直为 0。
my_app_development=# SELECT content, ts_rank(to_tsvector('microposts.content'), query)
AS rank FROM microposts, to_tsquery('sit') query WHERE microposts.content @@ query
ORDER BY rank DESC LIMIT 10;
content | rank
---------------------------------------------------+------
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Vel sit ut qui aperiam aut sunt. | 0
Vel sit ut qui aperiam aut sunt. | 0
Vel sit ut qui aperiam aut sunt. | 0
Vel sit ut qui aperiam aut sunt. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
(10 rows)
这是预期的行为吗?如果是,我做错了什么。
干杯。
李.
您正在寻找每一行中相同短语的比率 to_tsvector('microposts.content')
,您应该使用 ts_rank(to_tsvector(content),query)
此外,我认为您应该定义语言以获得准确的结果:
SELECT content, ts_rank(to_tsvector('latin',content), query)
AS rank FROM microposts, to_tsquery('latin','sit') query WHERE microposts.content @@ query
ORDER BY rank DESC LIMIT 10;
我也不确定 sit
是否根本不是要忽略的停用词...
我一直想在我的网站中加入全文搜索,但搜索结果的排名 return 阻碍了我。 docs 展示了如何做到这一点,但我选择的所有 post 条目结果一直为 0。
my_app_development=# SELECT content, ts_rank(to_tsvector('microposts.content'), query)
AS rank FROM microposts, to_tsquery('sit') query WHERE microposts.content @@ query
ORDER BY rank DESC LIMIT 10;
content | rank
---------------------------------------------------+------
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
Vel sit ut qui aperiam aut sunt. | 0
Vel sit ut qui aperiam aut sunt. | 0
Vel sit ut qui aperiam aut sunt. | 0
Vel sit ut qui aperiam aut sunt. | 0
Dolorem sed omnis iusto sit inventore quia dolor. | 0
(10 rows)
这是预期的行为吗?如果是,我做错了什么。
干杯。
李.
您正在寻找每一行中相同短语的比率 to_tsvector('microposts.content')
,您应该使用 ts_rank(to_tsvector(content),query)
此外,我认为您应该定义语言以获得准确的结果:
SELECT content, ts_rank(to_tsvector('latin',content), query)
AS rank FROM microposts, to_tsquery('latin','sit') query WHERE microposts.content @@ query
ORDER BY rank DESC LIMIT 10;
我也不确定 sit
是否根本不是要忽略的停用词...