ここにランキングするにはフルテキストを使用する辞書をテーブルに "転がす"ことができるかどうか分かりません。しかし、あなたは、いくつかのprimityveは、例えば、非常に簡単にランク付けして、それを照会することができます
t=# with a(a) as (values('a b c'),('a c d'),('b e f'),('r b t'),('q w'))
, b(i,b) as (values(1,'a b'), (2,'e'), (3,'b'))
, p as (select unnest(string_to_array(b.b,' ')) arr,i from b)
select a phrases,arr match_words,count(1) over (partition by arr) words_in_matches, count(1) over (partition by i) matches,i from a left join p on a.a like '%'||arr||'%';
phrases | match_words | words_in_matches | matches | i
---------+-------------+------------------+---------+---
r b t | b | 6 | 5 | 1
a b c | b | 6 | 5 | 1
b e f | b | 6 | 5 | 1
a b c | a | 2 | 5 | 1
a c d | a | 2 | 5 | 1
b e f | e | 1 | 1 | 2
r b t | b | 6 | 3 | 3
a b c | b | 6 | 3 | 3
b e f | b | 6 | 3 | 3
q w | | 1 | 1 |
(10 rows)
- フレーズは、あなたの大きなテーブルからの行です。
- match_wordsは、(スペースで分割さ)あなたの小さなテーブルからトークン
- あるフレーズに
- 試合をトークンの量をwords_in_matches小さなテーブルからフレーズのI指数
- 小さなテーブルのフレーズから大きなテーブルのフレーズにマッチの量であります
つまり、あなたの答えを
感謝...ランキングのいくつかの並べ替えを取得するために、第三または第四のカラムで注文することができます。私はかなりpgsqlに新しいので、私は単にそれを理解していない。あなたはトークンをどういう意味ですか? –
トークンは単語ですが、この場合は簡単にするためスペースで区切った文字を使用しました。コンセプトのhttps://www.postgresql.org/docs/current/static/textsearch-controls.html#textsearch-parsing-documentsを読んでください。 –