Joe*_*Joe 7 postgresql full-text-search
我在一张桌子上有一个全文索引。是否可以检索索引(gist或gin)中使用的术语集?如果可能的话用重量?
澄清:
如果我有下表:
create table "test" (id integer, thing tsvector);
Run Code Online (Sandbox Code Playgroud)
然后我在它上面做一个 GIST 索引:
create index thing_index on test using gist (thing);
Run Code Online (Sandbox Code Playgroud)
然后是一些数据:
insert into test (id, thing)
values (1, 'one'),(2, 'two'), (3, 'three'), (4, 'one'), (5, 'two');
Run Code Online (Sandbox Code Playgroud)
该索引thing_index将包含以下映射:
'one' => {1, 4}
'two' => {2, 5}
'three' => {3}
Run Code Online (Sandbox Code Playgroud)
我想从索引中获得以下响应:
'one',
'two',
'three'
Run Code Online (Sandbox Code Playgroud)
甚至可能有排名:
'one' => 2
'two' => 2
'three' => 1
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过扫描和构建我自己的索引来自己做这件事,但如果可能的话,我想从 Postgres 中获取它。
如果我正确理解你的问题并且根本不清楚,那么你正试图撤回有关 id 与值相关的信息。我不认为你可以从 PostgreSQL 的索引中提取它,因为索引不会包含可见性信息,所以你将有大量的随机 IO 并等待盘片转动。
您的测试用例的查询是:
select thing, array_agg(id) from test group by thing;
Run Code Online (Sandbox Code Playgroud)
假设您的版本足够高,可以拥有 array_agg。
在我的系统(9.1)中,这给了我:
chris=> select thing, array_agg(id) from test group by thing;
thing | array_agg
---------+-----------
'one' | {1,4}
'two' | {2,5}
'three' | {3}
(3 rows)
Run Code Online (Sandbox Code Playgroud)
这就是您正在寻找的,对吧?
| 归档时间: |
|
| 查看次数: |
281 次 |
| 最近记录: |