我有一列(artist_name),其中包含表中的艺术家名称。我还有另一列(artist_name_search),该列由触发器自动填充以进行全文搜索。
要求是,当搜索单词“ Pink”时,我应该能够检索艺术家“ Pink”和“ P!nk”。我可以使用ts_vector和ts_query分别查询每个艺术家的姓名,但是在搜索单词“ Pink”时无法获得组合结果
感谢您对解决此问题的帮助。谢谢!
--Definition of trigger that auto populates the tsvector column
CREATE TRIGGER artists_tsvector_search
BEFORE INSERT OR UPDATE OF artist_name
ON artists
FOR EACH ROW
BEGIN
NEW.artist_name_search = to_tsvector('english',NEW.artist_name);
END;
--Below query searches for the word "Pink"
select artist_name_search, artist_name from artists where to_tsquery('Pink') @@ artist_name_search
--Below query searches for the word "P!nk"
select artist_name_search, artist_name from artists where to_tsquery('P\!nk') @@ artist_name_search