【问题标题】:Error with pg_search multisearch after initializing tsearch, trigram初始化 tsearch、trigram 后 pg_search multisearch 出错
【发布时间】:2012-05-15 01:54:39
【问题描述】:

我让 pg_search 使用多重搜索在我的 Rails 3.2.3 应用程序上工作。然后我在 this post. 中实现了nertzy(pg_search 的作者)提供的初始化程序。现在,当我运行搜索时,我收到以下错误:

PG::Error: ERROR:  operator does not exist: text % unknown
LINE 1: ... ((coalesce("pg_search_documents"."content", '')) % 'searchterm...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

我的视图是使用以下代码呈现的:

<%= @pg_search_documents.each do |pg_search_document| %>
  <%= pg_search_document.searchable.title %>
<% end %>

我的其余设置可以在 here. 找到任何帮助非常感谢。

【问题讨论】:

  • 您找到答案了吗?我遇到了同样的问题。
  • 嘿约翰。我想回忆一下,但我想我通过删除三元组功能(不管是什么)解决了这个问题。所以删除这一行::trigram =&gt; {} 为我修复了它。
  • 是的,深入挖掘我发现您必须安装 trigram 包才能使其工作。 pg_search 页面上有一些文档。

标签: ruby-on-rails-3 full-text-search pg-search


【解决方案1】:

我之前也遇到过这个问题。只是为了向其他可能遇到麻烦的人澄清......这是安装扩展的方法:

  1. 通过运行创建一个新的迁移

    bundle exec rails g migration add_trigram_extension
    
  2. 在您的迁移中,粘贴以下代码:

    def up
        execute "create extension pg_trgm"
    end
    
    def down
        execute "drop extension pg_trgm"
    end
    
  3. 使用bundle exec rake db:migrate运行迁移

这在本地对我有用。您可以与 pg_search 一起使用的一些扩展或配置需要更新版本的 Postgres。为了在 heroku 上使用某些扩展,您可能需要使用开发数据库。

更新:据我了解,heroku 已发布滚动升级,现在每个人都默认运行更新版本的 pg。以上应该可以在 heroku 上运行,而无需升级您的数据库。

【讨论】:

  • 我是 pg_search 的作者和维护者,@stephenalexbrowne 所说的完全正确。更多信息请访问github.com/Casecommons/pg_search/wiki/…
  • @nertzy 我已经关注到 T 并且它在本地和 Heroku 上因PG::Error: ERROR: operator does not exist: text % unknown 错误而中断。我在提供 trigram 包的共享数据库上,我通过 homebrew 安装了 PG,那里有 trigram 包。
  • @Simpleton 通常你会看到类似text % text,而不是text % unknown。也许您可以在github.com/Casecommons/pg_search/issues 上打开一个问题并粘贴到您的查询中?
  • 酷,如果我有时间,今天晚些时候会打开一个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-29
  • 2013-01-02
  • 2016-09-25
  • 2020-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多