我想你应该考虑full text search。
在postgresql中,您要做的是创建一个类型为tsvector的列,该列将包含其他列的分解版本。它会照顾stemming这个词。
alter table TABLE add column tsv_description tsvector;
然后你需要填充它。
UPDATE TABLE SET tsv_description = (to_tsvector('pg_catalog.english',coalesce(searchname, '')) || (to_tsvector('pg_catalog.english',coalesce(searchbrand, '')) || to_tsvector('pg_catalog.english',coalesce(othercol, ''));
然后你就可以查询使用to_tsquery像这样:
select * from TABLE where tsvdescription @@ plainto_tsquery('pg_catalog.english','my super full text query');
您还可以列转换为上飞,但它的速度较慢tsvectors。
select * from TABLE where to_tsvector(searchname) || to_tsvector(searcbrand) @@ plainto_tsquery('pg_catalog.english','tocino');
*叹*是这么简单?谢谢你,试试这个。 – Gabrie
决定去你的第二个建议,并创建一个单独的表,只有一个字段和全文索引。谢谢 – Gabrie