Module: Workarea::Elasticsearch::Document

Extended by:
ActiveSupport::Concern
Included in:
Search::Admin, Search::Help, Search::Storefront
Defined in:
lib/workarea/elasticsearch/document.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



17
18
19
# File 'lib/workarea/elasticsearch/document.rb', line 17

def all
  Constants.find(:search_documents)
end

.current_index_prefixObject



21
22
23
24
# File 'lib/workarea/elasticsearch/document.rb', line 21

def current_index_prefix
  locale = I18n.locale.to_s.underscore
  "#{Workarea.config.site_name.optionize}_#{Rails.env}_#{locale}"
end

Instance Method Details

#as_bulk_document(action = :index) ⇒ Object



100
101
102
# File 'lib/workarea/elasticsearch/document.rb', line 100

def as_bulk_document(action = :index)
  as_document.merge(Serializer.serialize(model)).merge(bulk_action: action)
end

#as_documentObject

Raises:

  • (NotImplementedError)


93
94
95
96
97
98
# File 'lib/workarea/elasticsearch/document.rb', line 93

def as_document
  raise(
    NotImplementedError,
    "#{self.class} must implement #as_document to be saved"
  )
end

#destroy(options = {}) ⇒ Object



111
112
113
# File 'lib/workarea/elasticsearch/document.rb', line 111

def destroy(options = {})
  I18n.for_each_locale { self.class.delete(id, options) }
end

#initialize(model, options = {}) ⇒ Object



88
89
90
91
# File 'lib/workarea/elasticsearch/document.rb', line 88

def initialize(model, options = {})
  @model = model
  @options = options
end

#save(options = {}) ⇒ Object



104
105
106
107
108
109
# File 'lib/workarea/elasticsearch/document.rb', line 104

def save(options = {})
  I18n.for_each_locale do
    document = as_document.merge(Serializer.serialize(model))
    self.class.save(document, options)
  end
end