Module: Elastictastic::Document::InstanceMethods

Defined in:
lib/elastictastic/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#id ⇒ Object

Returns the value of attribute id.



50
51
52
# File 'lib/elastictastic/document.rb', line 50

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object



85
86
87
# File 'lib/elastictastic/document.rb', line 85

def ==(other)
  index == other.index && id == other.id
end

#elasticsearch_hit=(hit) ⇒ Object

:nodoc:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/elastictastic/document.rb', line 56

def elasticsearch_hit=(hit) #:nodoc:
  @id = hit['_id']
  @index = Index.new(hit['_index'])
  persisted!

  doc = {}
  doc.merge!(hit['_source']) if hit['_source']
  fields = hit['fields']
  if fields
    unflattened_fields =
      Util.unflatten_hash(fields.reject { |k, v| v.nil? })
    if unflattened_fields.has_key?('_source')
      doc.merge!(unflattened_fields.delete('_source'))
    end
    doc.merge!(unflattened_fields)
  end
  self.elasticsearch_doc=(doc)
end

#index ⇒ Object



80
81
82
83
# File 'lib/elastictastic/document.rb', line 80

def index
  return @index if defined? @index
  @index = Index.default
end

#initialize(attributes = {}) ⇒ Object



52
53
54
# File 'lib/elastictastic/document.rb', line 52

def initialize(attributes = {})
  self.class.current_scope.initialize_instance(self)
end

#inspect ⇒ Object



89
90
91
92
93
94
95
# File 'lib/elastictastic/document.rb', line 89

def inspect
  inspected = "#<#{self.class.name} id: #{id}, index: #{index.name}"
  attributes.each_pair do |attr, value|
    inspected << ", #{attr}: #{value.inspect}"
  end
  inspected << ">"
end