我正在使用postgresql 9.6。我想了解ts_rank
我有一个短语“一二四”,我的搜索查询是“一二三”所以我试图获得所有可能组合的ts_rank,如下所示。
select
ts_rank(to_tsvector('one two four'), to_tsquery('one')) AS one,
ts_rank(to_tsvector('one two four'), to_tsquery('two')) AS two,
ts_rank(to_tsvector('one two four'), to_tsquery('three')) AS three,
ts_rank(to_tsvector('one two four'), to_tsquery('one | two | three')) AS oneortwoorthree,
ts_rank(to_tsvector('one two four'), to_tsquery('one & two & three')) AS oneandtwoandthree,
ts_rank(to_tsvector('one two four'), to_tsquery('(one & two)')) AS mix2_1,
ts_rank(to_tsvector('one two four'), to_tsquery('(two & three)')) AS mix2_2,
ts_rank(to_tsvector('one two four'), to_tsquery('(one & three)')) AS mix2_3,
ts_rank(to_tsvector('one two four'), to_tsquery('(one & two) | three')) AS mix3_1,
ts_rank(to_tsvector('one two four'), to_tsquery('(two & three) | one')) AS mix3_2,
ts_rank(to_tsvector('one two four'), to_tsquery('(one & three) | two')) AS mix3_3
我得到以下结果:
one: 0.0607927
two: 0.0607927
three: 0
oneortwoorthree: 0.0405285
oneandtwoandthree: 0.0991032
mix2_1: 0.0991032
mix2_2: 1e-20
mix2_3: 1e-20
mix3_1: 0.0405285
mix3_2: 0.0405285
mix3_3: 0.0405285
问题1: 我期待
ts_rank(to_tsvector('one two four'), to_tsquery('one & two & three')) AS oneandtwoandthree =
0因为一个&两个&三个不存在。
问题2:
的等级如何ts_rank(to_tsvector('one two four'), to_tsquery('one | two | three')) AS oneortwoorthree = 0.0405285
和
ts_rank(to_tsvector('one two four'), to_tsquery('(one & two) | three')) AS mix3_1, = 0.0405285
是相同的
问题3:
我期待
的ts_rank ts_rank(to_tsvector('one two four'), to_tsquery('one | two | three')) AS oneortwoorthree
= 0.0405285
应该大于
ts_rank(to_tsvector('one two four'), to_tsquery('one')) AS one
= 0.0607927
而反之。很有可能三个单词中的任何一个都可以存在于短语中而不是单个单词。