Postgresql:如何使全文搜索忽略某些标记?
是否有一个神奇的函数或运算符可以忽略某些令牌Postgresql:如何使全文搜索忽略某些标记?,postgresql,full-text-search,Postgresql,Full Text Search,是否有一个神奇的函数或运算符可以忽略某些令牌 select to_tsvector('the quick. brown fox') @@ 'brown' -- returns true select to_tsvector('the quick,brown fox') @@ 'brown' -- returns true select to_tsvector('the quick.brown fox') @@ 'brown' -- returns false, should return t
select to_tsvector('the quick. brown fox') @@ 'brown' -- returns true
select to_tsvector('the quick,brown fox') @@ 'brown' -- returns true
select to_tsvector('the quick.brown fox') @@ 'brown' -- returns false, should return true
select to_tsvector('the quick/brown fox') @@ 'brown' -- returns false, should return true
恐怕你可能被卡住了。如果通过ts_debug运行术语,您将看到“quick.brown”被解析为主机名,“quick/brown”被解析为文件系统路径。遗憾的是,解析器真的没有那么聪明 我唯一的建议是对文本进行预处理,将这些标记转换为空格。您可以轻松地在plpgsql中创建一个函数来实现这一点
nicg=# select ts_debug('the quick.brown fox');
ts_debug
---------------------------------------------------------------------
(asciiword,"Word, all ASCII",the,{english_stem},english_stem,{})
(blank,"Space symbols"," ",{},,)
(host,Host,quick.brown,{simple},simple,{quick.brown})
(blank,"Space symbols"," ",{},,)
(asciiword,"Word, all ASCII",fox,{english_stem},english_stem,{fox})
(5 rows)
从上面可以看出,quick和brown没有代币