簡體   English   中英

pg search gem在Heroku上不起作用

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

我在Heroku上正確使用pg_search gem有問題。 在localhost上運行很好,但是當我嘗試在開發人員站點上搜索某些表達式時,始終顯示空結果。 我試圖檢查結果的對象,但是什么也沒顯示。 在heroku控制台中, com和PgSearch.multisearch(“ ruby​​”)可以正常工作。

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

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

視圖:

.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

當我嘗試搜索表達式時,下面有幾行具有注冊操作的代碼:ruby。 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)

如何解決問題?

您應該在Heroku控制台中編寫: rake pg_search:multisearch:rebuild[Vocabulary]有關更多信息,請檢查以下內容: 重建給定類的搜索文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM