我试图获得列出标签列表的最佳匹配项列表。 与下面的数据:Postgresql - 按排列数匹配
DROP TABLE IF EXISTS testing_items;
CREATE TEMP TABLE testing_items(
id bigserial primary key,
tags text[]
);
CREATE INDEX ON testing_items using gin (tags);
INSERT INTO testing_items (tags) VALUES ('{123,456, abc}');
INSERT INTO testing_items (tags) VALUES ('{222,333}');
INSERT INTO testing_items (tags) VALUES ('{222,555}');
INSERT INTO testing_items (tags) VALUES ('{222,123}');
INSERT INTO testing_items (tags) VALUES ('{222,123,555,666}');
我有标签222,555 and 666
。我怎样才能得到这样的列表?
ps:必须使用GIN索引,因为会有大量记录。
id matches
-- -------
5 3
3 2
2 1
4 1
编辑 编号1不应该出现在列表中,因为不匹配任何标签
1 0
这只返回匹配所有标签的项目 – Eduardo
对不起,我误解了这个问题。 – McNets
看一看:http://stackoverflow.com/a/24330181/3270427 – McNets