收集文献统计
函数ts_stat可用于检查配置和查找候选停用词。
1. ts_stat(sqlquery text, [ weights text, ]
2. OUT word text, OUT ndoc integer,
3. OUT nentry integer) returns setof record
sqlquery是一个包含SQL查询语句的文本,该SQL查询将返回一个tsvector。ts_stat执行SQL查询语句并返回一个包含tsvector中每一个不同的语素(词)的统计信息。返回信息包括:
- word text:词素。
- ndoc integer:词素在文档(tsvector)中的编号。
- nentry integer:词素出现的频率。
如果设置了权重条件,只有标记了对应权重的词素才会统计频率。例如,在一个文档集中检索使用频率最高的十个单词:
1. openGauss=# SELECT * FROM ts_stat('SELECT to_tsvector(''english'', sr_reason_sk) FROM tpcds.store_returns WHERE sr_customer_sk < 10') ORDER BY nentry DESC, ndoc DESC, word LIMIT 10;
2. word | ndoc | nentry
3. ------+------+--------
4. 32 | 2 | 2
5. 33 | 2 | 2
6. 1 | 1 | 1
7. 10 | 1 | 1
8. 13 | 1 | 1
9. 14 | 1 | 1
10. 15 | 1 | 1
11. 17 | 1 | 1
12. 20 | 1 | 1
13. 22 | 1 | 1
14. (10 rows)
同样的情况,但是只计算权重为A或者B的单词使用频率:
1. openGauss=# SELECT * FROM ts_stat('SELECT to_tsvector(''english'', sr_reason_sk) FROM tpcds.store_returns WHERE sr_customer_sk < 10', 'a') ORDER BY nentry DESC, ndoc DESC, word LIMIT 10;
2. word | ndoc | nentry
3. ------+------+--------
4. (0 rows)
