Class: Searchkick::RecordData

Inherits:
Object
  • Object
show all
Defined in:
lib/searchkick/record_data.rb

Constant Summary collapse

TYPE_KEYS =
["type", :type]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, record) ⇒ RecordData

Returns a new instance of RecordData.



7
8
9
10
# File 'lib/searchkick/record_data.rb', line 7

def initialize(index, record)
  @index = index
  @record = record
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



5
6
7
# File 'lib/searchkick/record_data.rb', line 5

def index
  @index
end

#recordObject (readonly)

Returns the value of attribute record.



5
6
7
# File 'lib/searchkick/record_data.rb', line 5

def record
  @record
end

Instance Method Details

#delete_dataObject



24
25
26
# File 'lib/searchkick/record_data.rb', line 24

def delete_data
  {delete: record_data}
end

#document_type(ignore_type = false) ⇒ Object



33
34
35
# File 'lib/searchkick/record_data.rb', line 33

def document_type(ignore_type = false)
  index.klass_document_type(record.class, ignore_type)
end

#index_dataObject



12
13
14
15
16
# File 'lib/searchkick/record_data.rb', line 12

def index_data
  data = record_data
  data[:data] = search_data
  {index: data}
end

#record_dataObject



37
38
39
40
41
42
43
44
45
# File 'lib/searchkick/record_data.rb', line 37

def record_data
  data = {
    _index: index.name,
    _id: search_id
  }
  data[:_type] = document_type if Searchkick.server_below7?
  data[:routing] = record.search_routing if record.respond_to?(:search_routing)
  data
end

#search_idObject



28
29
30
31
# File 'lib/searchkick/record_data.rb', line 28

def search_id
  id = record.respond_to?(:search_document_id) ? record.search_document_id : record.id
  id.is_a?(Numeric) ? id : id.to_s
end

#update_data(method_name) ⇒ Object



18
19
20
21
22
# File 'lib/searchkick/record_data.rb', line 18

def update_data(method_name)
  data = record_data
  data[:data] = {doc: search_data(method_name)}
  {update: data}
end