Class: SirvRestApi::SearchResult

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

Overview

Search result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ SearchResult

Returns a new instance of SearchResult.



216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/sirv_rest_api/models.rb', line 216

def initialize(data = {})
  raw_hits = data["hits"] || []
  @hits = raw_hits.map do |hit|
    # Handle Elasticsearch _source format
    source = hit["_source"] || hit
    FileInfo.new(source)
  end
  # Handle Elasticsearch total format
  total_data = data["total"]
  @total = total_data.is_a?(Hash) ? total_data["value"] : total_data
  @scroll_id = data["scrollId"]
end

Instance Attribute Details

#hitsObject

Returns the value of attribute hits.



214
215
216
# File 'lib/sirv_rest_api/models.rb', line 214

def hits
  @hits
end

#scroll_idObject

Returns the value of attribute scroll_id.



214
215
216
# File 'lib/sirv_rest_api/models.rb', line 214

def scroll_id
  @scroll_id
end

#totalObject

Returns the value of attribute total.



214
215
216
# File 'lib/sirv_rest_api/models.rb', line 214

def total
  @total
end