我在一个名为 Name 的类中有一个 pg_search_scope ,如下所示:
pg_search_scope :fuzzy_search,
:against => [:surname, :forename, :other_names],
:using => {
dmetaphone: {
tsvector_column: 'dmetaphone_search_vector'
},
tsearch: {
dictionary: 'english',
tsvector_column: 'dictionary_search_vector'
}
},
:ranked_by => ":trigram"
我需要针对范围运行 SELECT 并返回选择性列。我排除了以下待办事项:
Name.select(:surname).fuzzy_search('smith')
但这会产生:
SELECT surname, \"names\".*, ((similarity((coalesce(\"names\".\"surname\"::text, '') || ' ' || coalesce(\"names\".\"forename\"::text, '') || ' ' || coalesce(\"names\".\"other_names\"::text, '')), 'smith'))) AS pg_search_rank FROM \"names\" WHERE (((\"names\".\"dmetaphone_search_vector\") @@ (to_tsquery('simple', ''' ' || pg_search_dmetaphone('smith') || ' '''))) OR ((\"names\".\"dictionary_search_vector\") @@ (to_tsquery('english', ''' ' || 'smith' || ' ''')))) ORDER BY pg_search_rank DESC, \"names\".\"id\" ASC
所以我们可以看到\"names\".*
查询中的叶子,当然会返回所有列。
还有人遇到这个吗?有什么建议么?
:)