Module: Runes::Orm::InstanceMethods

Defined in:
lib/runes/orm/active_record.rb

Instance Method Summary collapse

Instance Method Details

#add_object_to_indexObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/runes/orm/active_record.rb', line 28

def add_object_to_index
  begin
    if $es_client.search("_id: #{self.id}", :index => self.class.index_name, :type => self.class.type_name).hits == []
      $es_client.index(self.to_json, :id => self.id, :index => self.class.index_name, :type => self.class.type_name)
    else
      return true
    end
  rescue ElasticSearch::RequestError
    $es_client.index(self.to_json, :id => self.id, :index => self.class.index_name, :type => self.class.type_name)
  end
end

#destroy_object_from_indexObject



24
25
26
# File 'lib/runes/orm/active_record.rb', line 24

def destroy_object_from_index
  $es_client.delete(self.id.to_s, :index => self.class.index_name, :type => self.class.type_name)
end