Question

On localhost and my Heroku staging app, pg_search is working just fine.

On my Heroku product app, pg_search is still showing search results for my Footnote model (which I no longer want to include) in addition to the Reference model (which I still want to include).

I have...

# /app/models/reference.rb
class Reference < ActiveRecord::Base
  has_paper_trail
  include PgSearch
  multisearchable :against => [:source_text, :citation]
end

I have removed include PgSearch from my /app/models/footnote.rb.

My process starts with manually allocating some workers to the app. (Which I normally do automatically using workless.)

Then I do:

$ heroku run rails console --app testivate
Running `rails console` attached to terminal... up, run.2840
Connecting to database specified by DATABASE_URL
Loading production environment (Rails 3.2.11)
irb(main):001:0> PgSearch::Footnote.delete_all
NameError: uninitialized constant PgSearch::Footnote
irb(main):002:0> PgSearch::Reference.delete_all
irb(main):003:0> PgSearch::Multisearch.rebuild(Reference)
   (1.3ms)  BEGIN
  SQL (56.2ms)  DELETE FROM "pg_search_documents" WHERE "pg_search_documents"."searchable_type" = 'Reference'
   (1279.8ms)  INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
 SELECT 'Reference' AS searchable_type,
 "references".id AS searchable_id,
 (
 coalesce("references".source_text::text, '') || ' ' || coalesce("references".citation::text, '')
 ) AS content,
 '2013-04-02 01:05:09.330250' AS created_at,
 '2013-04-02 01:05:09.330250' AS updated_at
 FROM "references"

   (33.8ms)  COMMIT
=> #<PG::Result:0x00000006c849b0>
irb(main):004:0>

The last step returns its result, #<PG::Result:0x00000006c849b0>, instantly, despite the fact that I've just asked pg_search to index 53 documents of between 3000 and 15,000 words each.

Can I assume the rebuild process is underway? Is there some way of confirming when it's complete so I can scale back the worker processes? (And do I need to allocate worker processes to this anyway?)

BTW, the following approach also takes just seconds, which doesn't seem right:

$ heroku run rake pg_search:multisearch:rebuild[Reference] --app testivate
Running `rake pg_search:multisearch:rebuild[Reference]` attached to terminal... up, run.3303
Connecting to database specified by DATABASE_URL
   (1.5ms)  BEGIN
  SQL (95.4ms)  DELETE FROM "pg_search_documents" WHERE "pg_search_documents"."searchable_type" = 'Reference'
   (1070.3ms)  INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
 SELECT 'Reference' AS searchable_type,
 "references".id AS searchable_id,
 (
 coalesce("references".source_text::text, '') || ' ' || coalesce("references".citation::text, '')
 ) AS content,
 '2013-04-02 01:10:07.355707' AS created_at,
 '2013-04-02 01:10:07.355707' AS updated_at
 FROM "references"

   (103.3ms)  COMMIT

After all these attempts, I still get instances of the Footnote model in my search results. How can I get rid of them?

Was it helpful?

Solution

It's a bit harsh, but heroku run rake db:migrate:redo did the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top