6

因此,假设我搜索“Blerg”。我有一个名为SomethingblergSomething 的项目。

如果我像这样在 postgres(和 rails)中进行 ILIKE 搜索:

where("name ILIKE ?", "%#{ 'Blerg' }%")

它将返回结果“SomethingBlergSomething”,因为它包含 Blerg。

有没有办法让更快的 tsvector 在一个单词中进行类似的搜索:

where("(to_tsvector('english', name) @@ to_tsquery(?))", ('Blerg' + ':*'))

上面的查询不会返回“SomethingBlergSomething”。

那么如何让 tsvector 在搜索单词时表现得像 ILIKE 一样。

4

1 回答 1

7

您知道附加模块pg_trgm提供的三元组搜索吗?这似乎比文本搜索更适合您的用例。

有了三元索引(GIN 或 GiST),您就可以使用原始ILIKE谓词并获得索引支持。为此,您需要 Postgres 9.1+。

细节:

于 2014-12-12T12:56:29.020 回答