Class: Celsius::Primo::Adapter::Mget

Inherits:
Operation
  • Object
show all
Defined in:
lib/celsius/primo/adapter/mget.rb

Overview

Mget is implemented by ordinary searches, because the original “get” of primo does not return the same amount of informations as a “search” for ids.

Because searching for to many ids at once might cause trouble, a mget is split up into n searches, to be more easy to digest by primo.

Constant Summary collapse

RECORDS_PER_SEARCH =
25

Instance Attribute Summary

Attributes inherited from Operation

#adapter

Instance Method Summary collapse

Methods inherited from Operation

#initialize

Constructor Details

This class inherits a constructor from Celsius::Primo::Adapter::Operation

Instance Method Details

#call(mget_request, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/celsius/primo/adapter/mget.rb', line 12

def call(mget_request, options = {})
  options = deep_stringify(options)

  search_results = search_requests_from(mget_request).map do |search_request|
    adapter.search(search_request, return_raw_response: options["return_raw_response"])
  end

  search_results.inject({"docs" => []}) do |mget_result, search_result|
    mget_result["docs"].concat(search_result["hits"]["hits"])
    return mget_result
  end
end

#search_requests_from(mget_request) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/celsius/primo/adapter/mget.rb', line 25

def search_requests_from(mget_request)
  mget_request["docs"].each_slice(RECORDS_PER_SEARCH).to_a.map.with_index do |array, index|
    {
      from: index * RECORDS_PER_SEARCH,
      size: RECORDS_PER_SEARCH,
      query: {
        ids: array.map { |element| element["_id"] }
      }
    }
  end
end