简体   繁体   English

pg search gem在Heroku上不起作用

[英]Pg search gem doesn't work on Heroku

I have problem with properly work pg_search gem on Heroku. 我在Heroku上正确使用pg_search gem有问题。 On localhost works great, but when I try to search some expression on developer site always display empty result. 在localhost上运行很好,但是当我尝试在开发人员站点上搜索某些表达式时,始终显示空结果。 I tried to inspect object of result, but nothing showed. 我试图检查结果的对象,但是什么也没显示。 In heroku console comand PgSearch.multisearch("ruby") working fine. 在heroku控制台中, com和PgSearch.multisearch(“ ruby​​”)可以正常工作。

vocabulary.rb vocabulary.rb

# == Schema Information
#
# Table name: vocabularies
#
#  id         :integer          not null, primary key
#  expression :string
#  meaning    :string
#  created_at :datetime         not null
#  updated_at :datetime         not null
#

class Vocabulary < ActiveRecord::Base
  include PgSearch
  multisearchable :against => [:expression, :meaning]
  belongs_to :user
  validates :expression, :meaning, presence: true
  default_scope -> { order(updated_at: :desc)}
end

VocabulariesController VocabulariesController

class VocabulariesController < ApplicationController
  def search
    if params[:search].present?
      @pg_search_documents = PgSearch.multisearch(params[:search]).paginate(:page => params[:page], :per_page => 4)
    else
      @pg_search_documents = Vocabulary.all
    end
  end
end

View: 视图:

.searchbar_min
  =render 'layouts/searchbar'
%table.table.table-striped
  %thead
    %tr
      %th Wyrażenie
      %th Znaczenie
      %th
      %th
      %th

  %tbody
    = will_paginate @pg_search_documents
    - @pg_search_documents.each do |pg_search_document|
      %tr
        =pg_search_document.inspect
        %td= pg_search_document.searchable.expression
        %td= HTML_Truncator.truncate(pg_search_document.searchable.meaning, 40).html_safe
        %td
          = link_to vocabulary_path(pg_search_document), class: "btn btn-link" do
            %i.glyphicon.glyphicon-eye-open
            Pokaż
        -if current_user && current_user.admin?
          %td
            = link_to edit_vocabulary_path(pg_search_document), class: "btn btn-link" do
              %i.glyphicon.glyphicon-edit
              Edytuj
          %td
            = link_to vocabulary_path(pg_search_document), :method => :delete, :data => { :confirm => 'Jesteś pewny/a?' }, class: "btn btn-link" do
              %i.glyphicon.glyphicon-trash
              Usuń
%br
  = will_paginate @pg_search_documents

Below there are few line of code with registered action when i try search expression: ruby. 当我尝试搜索表达式时,下面有几行具有注册操作的代码:ruby。 Heroku logs: Heroku日志:

2016-02-11T10:10:37.832351+00:00 heroku[router]: at=info method=GET path="/vocabularies/search?utf8=%E2%9C%93&search=ruby" host=uidictionary.herokuapp.com request_id=37e83ee8-db63-4b45-a70f-4eca54287db2 fwd="84.10.16.142" dyno=web.1 connect=1ms service=181ms status=200 bytes=4388
2016-02-11T10:10:38.104878+00:00 heroku[router]: at=info method=GET path="/assets/application-dd08fe2ece9bd6ce8ece8cf874543813ca1cab7fa569184002981bf9c3d5c2d8.css" host=uidictionary.herokuapp.com request_id=2803fdca-2057-430d-809c-7f4cf3cd4824 fwd="84.10.16.142" dyno=web.1 connect=1ms service=20ms status=304 bytes=133
2016-02-11T10:10:38.283719+00:00 heroku[router]: at=info method=GET path="/assets/application-073c4fa35429da031792509534cc1edc2d1c5fe7b72d6a51ad0c80df3d0636eb.js" host=uidictionary.herokuapp.com request_id=1eff89eb-ca19-4b28-a8bf-1117ed113dd9 fwd="84.10.16.142" dyno=web.1 connect=1ms service=28ms status=304 bytes=133
2016-02-11T10:10:39.019321+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=uidictionary.herokuapp.com request_id=c987cc45-848f-4ab9-a0fd-d9896b1b08e1 fwd="84.10.16.142" dyno=web.1 connect=1ms service=8ms status=304 bytes=133
2016-02-11T10:11:10.614151+00:00 heroku[router]: at=info method=GET path="/vocabularies/search?utf8=%E2%9C%93&search=ruby" host=uidictionary.herokuapp.com request_id=a1e0f447-305b-4aa6-956b-5dc2543eefad fwd="84.10.16.142" dyno=web.1 connect=1ms service=34ms status=200 bytes=4388
2016-02-11T10:11:10.584974+00:00 app[web.1]: Started GET "/vocabularies/search?utf8=%E2%9C%93&search=ruby" for 84.10.16.142 at 2016-02-11 10:11:10 +0000
2016-02-11T10:11:10.597016+00:00 app[web.1]:   Rendered layouts/_searchbar.html.haml (1.0ms)
2016-02-11T10:11:10.604687+00:00 app[web.1]:   PgSearch::Document Load (2.9ms)  SELECT  "pg_search_documents".* FROM "pg_search_documents" INNER JOIN (SELECT "pg_search_documents"."id" AS pg_search_id, (ts_rank((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))), (to_tsquery('simple', ''' ' || 'ruby' || ' ''')), 0)) AS rank FROM "pg_search_documents" WHERE (((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'ruby' || ' '''))))) AS pg_search_ce9b9dd18c5c0023f2116f ON "pg_search_documents"."id" = pg_search_ce9b9dd18c5c0023f2116f.pg_search_id  ORDER BY pg_search_ce9b9dd18c5c0023f2116f.rank DESC, "pg_search_documents"."id" ASC LIMIT 4 OFFSET 0
2016-02-11T10:11:10.611004+00:00 app[web.1]:   Rendered layouts/_bootstrap.html.haml (0.1ms)
2016-02-11T10:11:10.612747+00:00 app[web.1]: Completed 200 OK in 24ms (Views: 12.3ms | ActiveRecord: 7.1ms)
2016-02-11T10:11:10.588341+00:00 app[web.1]: Processing by VocabulariesController#search as HTML
2016-02-11T10:11:10.588375+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "search"=>"ruby"}
2016-02-11T10:11:10.591815+00:00 app[web.1]:   User Load (1.8ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["id", 2]]
2016-02-11T10:11:10.600817+00:00 app[web.1]:    (2.4ms)  SELECT COUNT(*) FROM "pg_search_documents" INNER JOIN (SELECT "pg_search_documents"."id" AS pg_search_id, (ts_rank((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))), (to_tsquery('simple', ''' ' || 'ruby' || ' ''')), 0)) AS rank FROM "pg_search_documents" WHERE (((to_tsvector('simple', coalesce("pg_search_documents"."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'ruby' || ' '''))))) AS pg_search_ce9b9dd18c5c0023f2116f ON "pg_search_documents"."id" = pg_search_ce9b9dd18c5c0023f2116f.pg_search_id
2016-02-11T10:11:10.612038+00:00 app[web.1]:   Rendered layouts/_navbar.html.haml (0.8ms)
2016-02-11T10:11:10.606390+00:00 app[web.1]:   Rendered vocabularies/search.html.haml within layouts/application (10.7ms)

How to resolve problem? 如何解决问题?

您应该在Heroku控制台中编写: rake pg_search:multisearch:rebuild[Vocabulary]有关更多信息,请检查以下内容: 重建给定类的搜索文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM