Class: PagesCore::SearchableDocument::Indexer

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/pages_core/searchable_document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record) ⇒ Indexer

Returns a new instance of Indexer.



15
16
17
# File 'app/models/concerns/pages_core/searchable_document.rb', line 15

def initialize(record)
  @record = record
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record.



13
14
15
# File 'app/models/concerns/pages_core/searchable_document.rb', line 13

def record
  @record
end

Class Method Details

.index_all!(scope) ⇒ Object



20
21
22
# File 'app/models/concerns/pages_core/searchable_document.rb', line 20

def index_all!(scope)
  scope.find_each { |r| new(r).index! }
end

Instance Method Details

#index!Object



25
26
27
28
29
30
31
32
33
34
35
# File 'app/models/concerns/pages_core/searchable_document.rb', line 25

def index!
  SearchDocument.transaction do
    record.search_documents.where.not(locale: locales).destroy_all
    locales.each do |locale|
      update_index(
        locale,
        localized_record(locale).search_document_attributes
      )
    end
  end
end