I've implemented full-text search using pg_search gem for my Rails application
我已经使用pg_search gem为我的Rails应用程序实现了全文搜索
My migration to create index looks like
我的创建索引的迁移看起来像
execute(<<-'eosql'.strip)
CREATE index mytable_fts_idx
ON mytable
USING gin(
(setweight(to_tsvector('english', coalesce("mytable"."name", '')), 'A') ||
' ' ||
setweight(to_tsvector('english', coalesce("mytable"."description",'')), 'B')
)
)
eosql
And my controller code looks like
我的控制器代码看起来像
pg_search_scope :full_text_search,
:against => [
:name, :description],
:using => {
:tsearch => {
:prefix => true,
:dictionary => "english",
:any_word => true
}
}
which works totally fine locally on Postgres 9.0.4. However, when I deploy the same to heroku and search for a sample query 'test', it throws up an error
在Postgres 9.0.4上本地完全正常。但是,当我将它部署到heroku并搜索示例查询'test'时,它会引发错误
PGError: ERROR: syntax error in tsquery: "' test ':*"
SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "mytable" WHERE (((to_tsvector('english', coalesce("mytable"."name", '')) || to_tsvector('english', coalesce("mytable"."description", ''))) @@ (to_tsquery('english', ''' ' || 'test' || ' ''' || ':*')))) LIMIT 12 OFFSET 0) subquery_for_count ):
Any suggestions on where I'm wrong and what I should be looking at to fix this error? Thanks.
有关我错在哪里以及我应该注意什么来解决此错误的任何建议?谢谢。
1 个解决方案
#1
13
I'm the main developer of pg_search
. Sorry that you ran into that problem! Right now there is a pg_search
bug when using :prefix
searches against PostgreSQL 8.3 (the default for Heroku).
我是pg_search的主要开发者。对不起,你遇到了这个问题!现在使用时会出现pg_search错误:对PostgreSQL 8.3(Heroku的默认值)进行前缀搜索。
https://github.com/Casecommons/pg_search/issues/10
https://github.com/Casecommons/pg_search/issues/10
It's my top priority right now. I'm still figuring out the best way to get the test suite to run against both 8.x and 9.x.
这是我现在的首要任务。我还在找出让测试套件针对8.x和9.x运行的最佳方法。
Update: Unfortunately, :prefix
searches don't work against PostgreSQL 8.3 at all. The functionality was introduced in 8.4. I've released pg_search
0.3.3 which improves the error message. Hopefully Heroku will upgrade to 9.0 across the board soon. I believe they want to do so, but they obviously can't just upgrade everyone wholesale without warning.
更新:不幸的是,:前缀搜索根本不适用于PostgreSQL 8.3。该功能在8.4中引入。我发布了pg_search 0.3.3,它改进了错误信息。希望Heroku很快就会升级到9.0。我相信他们想要这样做,但他们显然不能在没有警告的情况下升级所有批发商。
#1
13
I'm the main developer of pg_search
. Sorry that you ran into that problem! Right now there is a pg_search
bug when using :prefix
searches against PostgreSQL 8.3 (the default for Heroku).
我是pg_search的主要开发者。对不起,你遇到了这个问题!现在使用时会出现pg_search错误:对PostgreSQL 8.3(Heroku的默认值)进行前缀搜索。
https://github.com/Casecommons/pg_search/issues/10
https://github.com/Casecommons/pg_search/issues/10
It's my top priority right now. I'm still figuring out the best way to get the test suite to run against both 8.x and 9.x.
这是我现在的首要任务。我还在找出让测试套件针对8.x和9.x运行的最佳方法。
Update: Unfortunately, :prefix
searches don't work against PostgreSQL 8.3 at all. The functionality was introduced in 8.4. I've released pg_search
0.3.3 which improves the error message. Hopefully Heroku will upgrade to 9.0 across the board soon. I believe they want to do so, but they obviously can't just upgrade everyone wholesale without warning.
更新:不幸的是,:前缀搜索根本不适用于PostgreSQL 8.3。该功能在8.4中引入。我发布了pg_search 0.3.3,它改进了错误信息。希望Heroku很快就会升级到9.0。我相信他们想要这样做,但他们显然不能在没有警告的情况下升级所有批发商。