module Elasticsearch::Model::Globalize::OneIndexPerLanguage::InstanceMethods

Attributes

changed_attributes_by_locale[RW]
existence_of_documents[RW]

Public Instance Methods

delete_document(options={}) click to toggle source
Calls superclass method
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 198
def delete_document(options={})
  current_locale_only = options.delete(:current_locale_only)
  if current_locale_only
    super(options)
  else
    translations.pluck(:locale).each do |locale|
      ::Globalize.with_locale(locale) do
        super(options)
      end
    end
  end
end
document_type() click to toggle source
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 158
def document_type
  self.class.document_type
end
document_type_base(name=nil) click to toggle source
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 146
def document_type_base name=nil
  @document_type_base = name || @document_type_base || self.class.document_type_base
end
document_type_base=(name) click to toggle source
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 150
def document_type_base=(name)
  @document_type_base = name
end
index_document(options={}) click to toggle source
Calls superclass method
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 162
def index_document(options={})
  current_locale_only = options.delete(:current_locale_only)
  if current_locale_only
    super(options)
  else
    changed_attributes_by_locale.keys.each do |locale|
      ::Globalize.with_locale(locale) do
        super(options)
      end
    end
  end
end
index_name() click to toggle source
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 154
def index_name
  self.class.index_name
end
index_name_base(name=nil) click to toggle source
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 138
def index_name_base name=nil
  @index_name_base = name || @index_name_base || self.class.index_name_base
end
index_name_base=(name) click to toggle source
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 142
def index_name_base=(name)
  @index_name_base = name
end
update_document(options={}) click to toggle source
# File lib/elasticsearch/model/globalize/one_index_per_language.rb, line 175
def update_document(options={})
  changed_attributes_by_locale.keys.each do |locale|
    ::Globalize.with_locale(locale) do
      if existence_of_documents[locale]
        attributes = if respond_to?(:as_indexed_json)
          changed_attributes_by_locale[locale].select{ |k, v| as_indexed_json.keys.include? k }
        else
          changed_attributes_by_locale[locale]
        end

        client.update(
          { index: index_name,
            type: document_type,
            id: self.id,
            body: { doc: attributes } }.merge(options)
        )
      else
        index_document(current_locale_only: true)
      end
    end
  end
end