加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – 初始化tsearch,trigram后pg_search multisea

发布时间:2020-12-16 22:59:04 所属栏目:百科 来源:网络整理
导读:我使用multisearch在我的Rails 3.2.3应用程序上运行了pg_search.然后我在 this post.中实现了nertzy(pg_search的作者)提供的初始化程序.现在当我运行搜索时出现以下错误: PG::Error: ERROR: operator does not exist: text % unknownLINE 1: ... ((coalesce
我使用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.任何帮助非常感谢.

解决方法

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

>通过运行创建新的迁移

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而无需升级数据库.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读