Class: Libis::Services::Primo::Search

Inherits:
Object
  • Object
show all
Includes:
GenericSearch, RestClient
Defined in:
lib/libis/services/primo/search.rb

Instance Attribute Summary

Attributes included from GenericSearch

#base, #host, #index, #num_records, #record_pointer, #session_id, #set_number, #term

Attributes included from RestClient

#client

Instance Method Summary collapse

Methods included from GenericSearch

#each, #next_record

Methods included from RestClient

#configure, #get, #post_data, #post_url, #put_data, #put_url

Constructor Details

#initialize(url = 'https://services.libis.be') ⇒ Search

Returns a new instance of Search.



15
16
17
# File 'lib/libis/services/primo/search.rb', line 15

def initialize(url = 'https://services.libis.be')
  configure(url)
end

Instance Method Details

#find(term, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/libis/services/primo/search.rb', line 24

def find(term, options = {})
  max_count = options.delete(:max_count) || 100
  result = []
  while result.size < max_count
    reply = query(term, options.merge(from: result.size + 1))
    max_count = [max_count, reply[:count]].min
    reply[:data].each do |record|
      next unless result.size < max_count
      result << record[:display]
    end
  end
  result
end

#query(query, options = {}) ⇒ Object



19
20
21
22
# File 'lib/libis/services/primo/search.rb', line 19

def query(query, options = {})
  index = options.delete(:index) || 'any'
  get 'search', {query: "#{index}:#{query}"}.merge(options)
end