San*_*idi 7 postgresql full-text-search
我正在使用 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
Run Code Online (Sandbox Code Playgroud)
我得到以下结果:
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
Run Code Online (Sandbox Code Playgroud)
问题 1: 我期待
ts_rank(to_tsvector('one two four'), to_tsquery('one & two & three')) AS oneandtwoandthree = 0 因为一&二&三不存在。
问题二: 排名如何
ts_rank(to_tsvector('one two four'), to_tsquery('one | two | three')) AS oneortwoorthree = 0.0405285
Run Code Online (Sandbox Code Playgroud)
和
ts_rank(to_tsvector('one two four'), to_tsquery('(one & two) | three')) AS mix3_1, = 0.0405285
Run Code Online (Sandbox Code Playgroud)
是一样的
问题 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
而它是相反的。三个词中的任何一个都可能存在于短语中,而不是单个词。