您在
tsvector
和
tsquery
价值观您应该使用一致的配置,例如:
select to_tsvector('norwegian', 'Importkompetanse Oslo AS')
@@ to_tsquery('norwegian', 'Importkompetanse&Oslo&AS');
SQLFiddle
这就是为什么它与
'simple'
配置(即
default
).
笔记
:你总是可以
debug
文本搜索
ts_debug()
:出厂价。
'Importkompetanse'
尚未被切断,
'importkompetans'
是这个词的恰当词素(在
'norwegian'
配置)。
关
:您使用了一个非常长的基于表达式的索引,只有在查询中也使用了精确的表达式时,才会使用该索引。您在示例中正确使用了它,但这会使查询变得非常长,如果稍后更改索引表达式,则需要确保所有“使用”都已更新。
您可以使用一个简单的(sql)函数来简化查询:
create or replace function col_tsvector(mytable)
returns tsvector
immutable
language sql
as $function$
return to_tsvector('norwegian',
coalesce($1.col1, '') || ' ' ||
coalesce($1.col2, '') || ' ' ||
coalesce($1.col3, '') || ' ' ||
coalesce($1.col4, '') || ' ' ||
coalesce($1.col5, '') || ' ' ||
coalesce($1.col6, '') || ' ' ||
coalesce($1.col7, ''))
$function$;
这样,您可以大大简化索引定义和;您的查询也是如此。(您甚至可以使用
attribute notation
.)