Class: PgSearch::Multisearch::Rebuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_search/multisearch/rebuilder.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, time_source = Time.method(:now)) ⇒ Rebuilder

Returns a new instance of Rebuilder.



6
7
8
9
10
11
# File 'lib/pg_search/multisearch/rebuilder.rb', line 6

def initialize(model, time_source = Time.method(:now))
  raise ModelNotMultisearchable, model unless model.respond_to?(:pg_search_multisearchable_options)

  @model = model
  @time_source = time_source
end

Instance Method Details

#rebuildObject



13
14
15
16
17
18
19
20
21
# File 'lib/pg_search/multisearch/rebuilder.rb', line 13

def rebuild
  if model.respond_to?(:rebuild_pg_search_documents)
    model.rebuild_pg_search_documents
  elsif conditional? || dynamic? || additional_attributes?
    model.find_each(&:update_pg_search_document)
  else
    model.connection.execute(rebuild_sql)
  end
end