我在Heroku上正确工作pg_search gem时遇到问题。在localhost上工作得很好,但是当我尝试在开发者网站上搜索某些表达式时,总是显示空结果。我试图检查结果的对象,但没有显示。在heroku控制台命令 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)
如何解决问题?
答案 0 :(得分:2)
你应该在Heroku控制台上写:
rake pg_search:multisearch:rebuild[Vocabulary]
有关详细信息,请检查:
Rebuilding search documents for a given class