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



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

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

#as_documentObject

Raises:

  • (NotImplementedError)


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

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

#destroy(options = {}) ⇒ Object



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

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

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



83
84
85
86
# File 'lib/workarea/elasticsearch/document.rb', line 83

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

#save(options = {}) ⇒ Object



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

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