云服务器内容精选

  • 操作步骤 创建一个文本搜索配置ts_conf,复制预定义的文本搜索配置english。 12 CREATE TEXT SEARCH CONFIGURATION ts_conf ( COPY = pg_catalog.english );CREATE TEXT SEARCH CONFIGURATION 创建Synonym词典。 假设同义词词典定义文件pg_dict.syn内容如下: 123 postgres pg pgsql pg postgresql pg 执行如下语句创建Synonym词典: 12345 CREATE TEXT SEARCH DICTIONARY pg_dict ( TEMPLATE = synonym, SYNONYMS = pg_dict, FILEPATH = 'obs://bucket01/obs.example.com accesskey=xxxxx secretkey=xxxxx region=cn-north-1' ); 创建一个Ispell词典english_ispell(词典定义文件来自开源词典)。 1234567 CREATE TEXT SEARCH DICTIONARY english_ispell ( TEMPLATE = ispell, DictFile = english, AffFile = english, StopWords = english, FILEPATH = 'obs://bucket01/obs.example.com accesskey=xxxxx secretkey=xxxxx region=cn-north-1'); 设置文本搜索配置ts_conf,修改某些类型的token对应的词典列表。关于token类型的详细信息,请参见解析器。 1234 ALTER TEXT SEARCH CONFIGURATION ts_conf ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part WITH pg_dict, english_ispell, english_stem; 在文本搜索配置中,选择设置不索引或搜索某些token类型。 12 ALTER TEXT SEARCH CONFIGURATION ts_conf DROP MAPPING FOR email, url, url_path, sfloat, float; 使用文本检索调测函数ts_debug()对所创建的词典配置ts_conf进行测试。 12345 SELECT * FROM ts_debug('ts_conf', 'PostgreSQL, the highly scalable, SQL compliant, open source object-relationaldatabase management system, is now undergoing beta testing of the nextversion of our software.'); 可以设置当前session使用ts_conf作为默认的文本搜索配置。此设置仅在当前session有效。 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627 \dF+ ts_conf Text search configuration "public.ts_conf"Parser: "pg_catalog.default" Token | Dictionaries -----------------+------------------------------------- asciihword | pg_dict,english_ispell,english_stem asciiword | pg_dict,english_ispell,english_stem file | simple host | simple hword | pg_dict,english_ispell,english_stem hword_asciipart | pg_dict,english_ispell,english_stem hword_numpart | simple hword_part | pg_dict,english_ispell,english_stem int | simple numhword | simple numword | simple uint | simple version | simple word | pg_dict,english_ispell,english_stemSET default_text_search_config = 'public.ts_conf';SETSHOW default_text_search_config; default_text_search_config ---------------------------- public.ts_conf(1 row)