使用 pg_search gem 在 Heroku 上进行全文搜索

发布于 2024-12-08 12:09:13 字数 1123 浏览 0 评论 0原文

我已经使用 pg_search gem 为我的 Rails 应用程序实现了全文搜索

我创建索引的迁移看起来

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

像 我的控制器代码看起来

pg_search_scope :full_text_search,
:against => [
  :name, :description],
:using => {
  :tsearch => {
    :prefix => true,
    :dictionary => "english",
    :any_word => true
  }
}

在 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 ):

关于我错在哪里以及我应该注意什么来修复此错误有什么建议吗?谢谢。

I've implemented full-text search using pg_search gem for my Rails application

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆一缕阳光ご 2024-12-15 12:09:13

我是 pg_search 的主要开发人员。很抱歉您遇到了这个问题!目前,使用 :prefix 搜索 PostgreSQL 8.3(Heroku 的默认设置)时存在 pg_search 错误。

https://github.com/Casecommons/pg_search/issues/10

这是我现在的首要任务。我仍在寻找让测试套件在 8.x 和 9.x 上运行的最佳方法。

更新:不幸的是,:prefix 搜索根本不适用于 PostgreSQL 8.3。该功能在 8.4 中引入。我发布了 pg_search 0.3.3,它改进了错误消息。希望 Heroku 很快全面升级到 9.0。我相信他们想这样做,但他们显然不能在没有警告的情况下批量升级每个人。

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).

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文