Sha256: 0e640d9f09fc766d26165c702e0172dc1a1e5d469aa450dae7906a8e296ea6e7

Contents?: true

Size: 1.13 KB

Versions: 31

Compression:

Stored size: 1.13 KB

Contents

# coding: utf-8
require 'json'

require 'libis/services/rest_client'
require 'libis/services/generic_search'

module Libis
  module Services
    module Primo

      class Search
        include ::Libis::Services::RestClient
        include ::Libis::Services::GenericSearch

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

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

        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

        protected

        def result_parser(response)
          JSON.parse(response, symbolize_names: true)
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
libis-services-1.1.0 lib/libis/services/primo/search.rb
libis-services-1.0.13 lib/libis/services/primo/search.rb
libis-services-1.0.12 lib/libis/services/primo/search.rb
libis-services-1.0.11 lib/libis/services/primo/search.rb
libis-services-1.0.10 lib/libis/services/primo/search.rb
libis-services-1.0.7 lib/libis/services/primo/search.rb
libis-services-1.0.6 lib/libis/services/primo/search.rb
libis-services-1.0.5 lib/libis/services/primo/search.rb
libis-services-1.0.2 lib/libis/services/primo/search.rb
libis-services-1.0.1 lib/libis/services/primo/search.rb
libis-services-1.0.0 lib/libis/services/primo/search.rb
libis-services-0.2.1 lib/libis/services/primo/search.rb
libis-services-0.2.0 lib/libis/services/primo/search.rb
libis-services-0.1.18 lib/libis/services/primo/search.rb
libis-services-0.1.17 lib/libis/services/primo/search.rb
libis-services-0.1.16 lib/libis/services/primo/search.rb
libis-services-0.1.15 lib/libis/services/primo/search.rb
libis-services-0.1.14 lib/libis/services/primo/search.rb
libis-services-0.1.13 lib/libis/services/primo/search.rb
libis-services-0.1.12 lib/libis/services/primo/search.rb