初始化tsearch,trigram后,pg_search multisearch出错

时间:2012-05-15 01:54:39

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

我使用multisearch在我的Rails 3.2.3应用程序上运行了pg_search。然后我在 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.非常感谢任何帮助。

1 个答案:

答案 0 :(得分:11)

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

  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

  4. 运行迁移

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

    更新:据我所知,heroku已经发布滚动升级,现在每个人都默认运行更新版本的pg。以上内容适用于heroku而无需升级数据库。

相关问题