我可以在 postgres ts_vector / ts_query 全文搜索中禁用字典吗?

Dha*_*kar 2 postgresql full-text-search postgresql-9.1

我需要对机器语言进行文本搜索。如果我使用任何可用的文本搜索词典,ts_vectors 就会搞砸。

前任。move -> 变成 mov 并且我的搜索失败了。

任何想法如何索引非语言单词?

谢谢!

Lau*_*lbe 6

你试过simple用空的停用词文件查字典吗?

创建一个空的停用词文件$(pg_config --sharedir)/tsearch_data/empty.stop并运行:

CREATE TEXT SEARCH DICTIONARY machine (
   TEMPLATE = pg_catalog.simple,
   STOPWORDS = empty
);

CREATE TEXT SEARCH CONFIGURATION machine (
   PARSER = default
);

ALTER TEXT SEARCH CONFIGURATION machine
   ADD MAPPING FOR asciiword, word, numword, asciihword, hword,
                   numhword, hword_asciipart, hword_part,
                   hword_numpart, email, protocol, url, host,
                   url_path, file, sfloat, float, int, uint,
                   version, tag, entity, blank
   WITH machine;
Run Code Online (Sandbox Code Playgroud)

然后你可以得到:

test=> SELECT * FROM ts_debug('machine', 'move');
   alias   |   description   | token | dictionaries | dictionary | lexemes
-----------+-----------------+-------+--------------+------------+---------
 asciiword | Word, all ASCII | move  | {machine}    | machine    | {move}
(1 row)
Run Code Online (Sandbox Code Playgroud)

如果您希望默认使用此配置(因此您不必一直指定'machine'),请default_text_search_config适当更改参数。