【问题标题】:postgres full text search word countpostgres全文搜索字数
【发布时间】:2012-07-25 13:49:21
【问题描述】:

我一直在玩 postgres 中的全文搜索,我想知道,是否可以返回所有行的总字数?

所以,假设你有

 text_col
 _______
 'dog'
 'dog cat'
 'dog bird dog'

“狗”的数量应该是四个,“猫”的数量应该是一个,鸟也应该是一个。

现在我也将所有 tsvectors 保存到 gin 索引列中。

当然,这将跨越所有行,你可以说类似的话

select max(ts_count(text_col_tsvector)) from mytable;

(这是我编造的,但我希望你能大致了解)

是否只能返回词位的计数,如果可以,如何返回返回的词位的字典(或数组)。

【问题讨论】:

    标签: postgresql full-text-search


    【解决方案1】:

    怎么样:

    select * from ts_stat('select text_col_tsvector from mytable')
    

    编辑: 你的意思是:

    with words as (
    select regexp_split_to_table(text_column , E'\\W+') as word
    from mytable
    )
    select word, count(*) as cnt from words group by 1 order by 2 desc 
    

    ?

    【讨论】:

    • 这很有用,可以让我进入写入方向,但这只会返回词位。我真正需要知道的是特定的字数,否则,返回与特定词位相关的单词字典(或数组)。
    • 这是我想要的 95%。我希望使用索引词法分析器,但我不确定是否可以返回到 lex 引用的单词字典。我使用了上面的内容并稍微添加了一些内容:with words as (select regexp_split_to_table(element_text, E'\\W+') as word from mytable ), word_lex as (select word, count(*) as cnt, to_tsvector(' English', COALESCE(word,'')) as t from words group by 1 order by 2 desc ) select * from word_lex WHERE t != ''
    • @JamesR 如果你使用 te 'simple' 字典来构建 tsvector 列,词位将是实际单词,第一个查询就可以了
    猜你喜欢
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-16
    • 2016-05-25
    • 1970-01-01
    相关资源
    最近更新 更多