Class: PgSearch::Multisearch::Rebuilder
- Inherits:
-
Object
- Object
- PgSearch::Multisearch::Rebuilder
- Defined in:
- lib/pg_search/multisearch/rebuilder.rb
Instance Method Summary collapse
-
#initialize(model, time_source = Time.method(:now)) ⇒ Rebuilder
constructor
Arguments.
-
#rebuild ⇒ Object
Populates search documents without first clearing existing documents.
Constructor Details
#initialize(model, time_source = Time.method(:now)) ⇒ Rebuilder
Arguments
modelActive Record model configured for multisearch.
time_sourceClock returning a timestamp for bulk inserts. Defaults to
Time.method(:now)and is called once per bulk rebuild socreated_atandupdated_atshare a timestamp.
Raises
- ModelNotMultisearchable
If
modelis not configured for multisearch.
16 17 18 19 20 21 |
# File 'lib/pg_search/multisearch/rebuilder.rb', line 16 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
#rebuild ⇒ Object
Populates search documents without first clearing existing documents. Uses the model's rebuild_pg_search_documents override when available; otherwise updates records individually for conditions, dynamic content, or additional attributes, and bulk-inserts for plain column content.
27 28 29 30 31 32 33 34 35 |
# File 'lib/pg_search/multisearch/rebuilder.rb', line 27 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 |