我在pg_search上使用multisearch在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.非常感谢您的帮助。
最佳答案
我也曾经遇到过这个问题。只是为了向可能遇到麻烦的其他人澄清...这是安装扩展程序的方法:
bundle exec rails g migration add_trigram_extension
def up
execute "create extension pg_trgm"
end
def down
execute "drop extension pg_trgm"
end
bundle exec rake db:migrate
进行运行迁移这为我在本地工作。可以与pg_search一起使用的某些扩展或配置需要较新版本的Postgres。为了在heroku上使用某些扩展,您可能需要使用dev数据库。
更新:据我了解,heroku已发布滚动升级,现在每个人默认都在运行较新版本的pg。上面的方法可以在heroku上运行,而无需升级数据库。
关于ruby-on-rails-3 - 初始化tsearch,Trigram后pg_search multisearch出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10593257/