AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 57058
Accepted
Neil McGuigan
Neil McGuigan
Asked: 2014-01-19 19:02:24 +0800 CST2014-01-19 19:02:24 +0800 CST 2014-01-19 19:02:24 +0800 CST

如何在 Postgres 文本搜索中使用 Ispell 字典?

  • 772

Postgres 可以在文本搜索中使用与 Ispell 兼容的字典,但不提供所需的文件。

postgresql windows
  • 4 4 个回答
  • 5325 Views

4 个回答

  • Voted
  1. Neil McGuigan
    2014-01-19T19:02:24+08:002014-01-19T19:02:24+08:00

    此示例使用加拿大英语词典,但您也可以与其他人一起尝试。

    这些是 Windows 所需的步骤:

    1. 打开http://src.chromium.org/svn/trunk/deps/third_party/hunspell_dictionaries/en_CA.dic
    2. 选择所有文本,复制并粘贴到 Text Mechanic:http ://textmechanic.co/Sort-Text-Lines.html 。在末尾添加换行符。
    3. 打开http://src.chromium.org/svn/trunk/deps/third_party/hunspell_dictionaries/en_CA.dic_delta
    4. 选择所有文本,复制它,然后将其粘贴到 Text Mechanic 中先前粘贴的文本下方。
    5. 滚动到顶部,选择并剪切第一行(应该是五位数字),并去掉换行符。
    6. 单击按字母顺序排列的按钮,然后等待文本排序。
    7. 选择所有文本并将其复制到剪贴板
    8. 以管理员身份打开 Windows 记事本
    9. 将步骤 7 中的文本粘贴到记事本中
    10. 将文件另存为en_ca.dict(使用 UTF-8 编码)到 Postgres 文本搜索文件夹。我的是 C:\Program Files\PostgreSQL\9.3\share\tsearch_data 。
    11. 打开http://src.chromium.org/svn/trunk/deps/third_party/hunspell_dictionaries/en_CA.aff,全选,复制粘贴到记事本。将文件作为en_ca.affix保存到 Postgres 文本搜索文件夹。

    在 PgAdmin 中,运行以下 SQL:

    create text search dictionary ispell_en_ca (
      template  =   ispell,
      dictfile  =   en_ca,
      afffile   =   en_ca,
      stopwords =   english
    );
    
    --make sure it works:
    select * from ts_lexize('ispell_en_ca', 'colours');
    
    /* 
    result:
    ts_lexize
    text[]
    {coloured,colour}
    */
    

    您将需要创建一个新的文本搜索配置来使用字典。

    • 7
  2. Best Answer
    Jeff
    2015-08-07T06:43:14+08:002015-08-07T06:43:14+08:00

    我编写了以下脚本来在运行 PostgreSQL 9.4 的 Ubuntu 14.04 上安装 en_us 字典。对于大多数情况,它应该很容易修改。

    #!/bin/bash
    cd /usr/share/postgresql/9.4/tsearch_data
    
    wget http://src.chromium.org/svn/trunk/deps/third_party/hunspell_dictionaries/en_US.dic
    wget http://src.chromium.org/svn/trunk/deps/third_party/hunspell_dictionaries/en_US.dic_delta
    wget http://src.chromium.org/svn/trunk/deps/third_party/hunspell_dictionaries/en_US.aff -O en_us.affix
    
    # Remove first line
    sed -i 1d en_US.dic
    
    # Concat the dic and dic_delta, sort alphabetically and remove the leading blank line (leaves the ending newline intact)
    cat en_US.dic en_US.dic_delta | sort > en_us.dict
    sed -i 1d en_us.dict
    
    # Set permissions
    chown -R postgres:postgres *
    
    sudo -u postgres psql -c "CREATE TEXT SEARCH DICTIONARY ispell_en_us (template  = ispell, dictfile = en_us, afffile = en_us, stopwords = english);"
    
    # Clean up source files
    rm en_US*
    
    • 7
  3. Ian Timothy
    2020-02-26T02:53:13+08:002020-02-26T02:53:13+08:00

    下载并安装必要的文件:

    英语.sh

    #!/bin/sh
    
    # https://www.cs.hmc.edu/~geoff/ispell.html
    wget http://www.cs.hmc.edu/~geoff/tars/ispell-3.4.00.tar.gz
    
    tar xvzf ispell-3.4.00.tar.gz
    
    cat ispell-3.4.00/languages/english/english.{0,1,2,3} | sort > english.dic
    cp ispell-3.4.00/languages/english/english.aff ./
    
    #iconv -f ISO_8859-1 -t UTF-8 -o english.affix english.aff
    #iconv -f ISO_8859-1 -t UTF-8 -o english.dict english.dic
    
    iconv -f ISO_8859-1 -t UTF-8 english.aff > english.affix
    iconv -f ISO_8859-1 -t UTF-8 english.dic > english.dict
    
    sudo cp english.{affix,dict} `pg_config --sharedir`/tsearch_data
    

    然后创建字典和配置:

    英语.sql

    -- first change the database name in the alter database command below
    
    -- create dictionary using files installed by english.sh script
    create text search dictionary english_ispell (
        template = ispell,
        dictfile = english,   -- english.dict
        afffile = english,   -- english.affix
        stopwords = english   -- english.stop (should exist in default installation)
    );
    
    -- create new configuation using the default as a template
    create text search configuration public.english ( copy = pg_catalog.english );
    
    -- show current configuration
    \dF+ public.english
    
    -- alter appropriate mappings to use new dictionary
    alter text search configuration public.english
        alter mapping for asciiword, asciihword, hword_asciipart, word, hword, hword_part
            with english_ispell, english_stem;
    
    -- show changed configuration
    \dF+ public.english
    
    -- test that the new configuation works
    select * from ts_debug(
        'public.english',
        'PostgreSQL, the highly scalable, SQL compliant, open source object-relational database management system, is now undergoing beta testing of the next version of our software.'
    );
    
    -- make database use new config
    alter database <name> set default_text_search_config to 'public.english';
    
    -- make session use new config
    set default_text_search_config to 'public.english';
    
    -- test that the new config is used by default
    select * from ts_debug(
        'PostgreSQL, the highly scalable, SQL compliant, open source object-relational database management system, is now undergoing beta testing of the next version of our software.'
    );
    
    • 3
  4. Craig Ringer
    2014-01-20T18:31:31+08:002014-01-20T18:31:31+08:00

    这在 PostgreSQL 手册的ISpell Dictionaries下有详细介绍。

    本质上,您只需CREATE TEXT SEARCH DICTIONARY (...)使用字典文件名、停用词列表等即可。

    • 2

相关问题

  • 运行时间偏移延迟复制的最佳实践

  • Oracle 可以在 Windows 上安装而不是管理员吗?

  • 存储过程可以防止 SQL 注入吗?

  • PostgreSQL 中 UniProt 的生物序列

  • PostgreSQL 9.0 Replication 和 Slony-I 有什么区别?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve