module Elos::Index::Indexable
Public Instance Methods
index(obj, destroy: false, unindex: false)
click to toggle source
# File lib/elos/index/indexable.rb, line 17 def index(obj, destroy: false, unindex: false) if !unindex && data = wrap_index_data(obj, destroy) params = { index: write_alias_name, type: type_name, body: data } params.merge!(id: obj.id) if obj.id client.index(params)['_id'] else begin client.delete(index: write_alias_name, type: type_name, id: obj.id) nil rescue Elasticsearch::Transport::Transport::Errors::NotFound end end end
index_data(index_data = nil)
click to toggle source
# File lib/elos/index/indexable.rb, line 9 def index_data(index_data = nil) if index_data self.index_data = index_data else self.class_variable_get(:@@index_data) end end
wrap_index_data(obj, destroy)
click to toggle source
# File lib/elos/index/indexable.rb, line 33 def wrap_index_data(obj, destroy) data = index_data.(obj) return unless data data.merge!(_destroyed: destroy) data[:json] = Elos::Index::Model::Object.encode(data[:json]) if data[:json] data end