Class: SearchKit::Models::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/search_kit/models/document.rb

Defined Under Namespace

Classes: AttributeNotFound

Instance Method Summary collapse

Constructor Details

#initialize(document_data = {}) ⇒ Document

Returns a new instance of Document.



12
13
14
15
16
17
18
# File 'lib/search_kit/models/document.rb', line 12

def initialize(document_data = {})
  super(
    source: document_data.fetch(:source, {}),
    id:     document_data.fetch(:id, nil),
    score:  document_data.fetch(:score, nil)
  )
end

Instance Method Details

#get(field) ⇒ Object



20
21
22
23
24
# File 'lib/search_kit/models/document.rb', line 20

def get(field)
  source.fetch(field.to_sym)
rescue KeyError
  fail AttributeNotFound, field
end