如何使用 Postgresql 在波斯语中使用全文搜索?

Kar*_*lom 5 postgresql full-text-search

我正在使用 Postgresql 9.6,我想运行这样的查询:

\n\n
select post_id \nfrom comments \nwhere to_tsvector(\'pg_catalog.persian\', comments.body) @@ to_tsquery(\'pg_catalog.persian\', \'\xda\xa9\xd8\xaa\xd8\xa7\xd8\xa8\') ;\n
Run Code Online (Sandbox Code Playgroud)\n\n

但波斯语不在 postgresql 字典支持的语言之列:

\n\n
postgres=# \\dF\n               List of text search configurations\n   Schema   |    Name    |              Description              \n------------+------------+---------------------------------------\n pg_catalog | danish     | configuration for danish language\n pg_catalog | dutch      | configuration for dutch language\n pg_catalog | english    | configuration for english language\n pg_catalog | finnish    | configuration for finnish language\n pg_catalog | french     | configuration for french language\n pg_catalog | german     | configuration for german language\n pg_catalog | hungarian  | configuration for hungarian language\n pg_catalog | italian    | configuration for italian language\n pg_catalog | norwegian  | configuration for norwegian language\n pg_catalog | portuguese | configuration for portuguese language\n pg_catalog | romanian   | configuration for romanian language\n pg_catalog | russian    | configuration for russian language\n pg_catalog | simple     | simple configuration\n pg_catalog | spanish    | configuration for spanish language\n pg_catalog | swedish    | configuration for swedish language\n pg_catalog | turkish    | configuration for turkish language\n(16 rows)\n
Run Code Online (Sandbox Code Playgroud)\n\n

所以我得到错误:

\n\n
\n

错误:文本搜索配置“pg_catalog.persian”不存在

\n
\n\n

我的默认数据库配置是英语:

\n\n
postgres=# show default_text_search_config;\n default_text_search_config \n----------------------------\n pg_catalog.english\n(1 row)\n
Run Code Online (Sandbox Code Playgroud)\n\n

我已经尝试过pg_catalog.simple,但它返回任何内容,而\xda\xa9\xd8\xaa\xd8\xa7\xd8\xa8.

\n\n

所以我想知道在这种情况下如何进行全文搜索以获得相关的波斯语结果?

\n

小智 5

用这个。

\n\n
select post_id \nfrom comments \nwhere to_tsvector(\'simple\', comments.body) @@ to_tsquery(\'simple\', \'\xda\xa9\xd8\xaa\xd8\xa7\xd8\xa8\') ;\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者

\n\n
select post_id \nfrom comments \nwhere to_tsvector(\'simple\', comments.body) @@ to_tsquery(\'\xda\xa9\xd8\xaa\xd8\xa7\xd8\xa8\') ;\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者使用这个扩展:

\n\n

https://pgroonga.github.io/tutorial/

\n