Sha256: cd89d3a63d680b61c1c4d4ff99c9c8254d06202a7270dc47cfe6db067848dd00

Contents?: true

Size: 1.19 KB

Versions: 49

Compression:

Stored size: 1.19 KB

Contents

module Ddr::Index
  class QueryResult < AbstractQueryResult

    PAGE_SIZE = 1000

    delegate :csv, to: :query

    def each(&block)
      if params[:rows]
        each_unpaginated(&block)
      else
        each_paginated(&block)
      end
    end

    def each_unpaginated(&block)
      conn.select(params).docs.each(&block)
    end

    def each_paginated(&block)
      pages.each { |pg| pg.each(&block) }
    end

    def pids
      Enumerator.new do |e|
        each do |doc|
          e << doc[Fields::PID]
        end
      end
    end

    def each_pid(&block)
      pids.each(&block)
    end

    def docs
      Enumerator.new do |e|
        each do |doc|
          e << DocumentBuilder.build(doc)
        end
      end
    end

    def all
      to_a
    end

    def pages
      num = 1
      Enumerator.new do |e|
        loop do
          pg = page(num)
          e << pg
          unless pg.has_next?
            break
          end
          num += 1
        end
      end
    end

    def page(num)
      page_params = params.dup
      page_size = page_params.delete(:rows) || PAGE_SIZE
      response = conn.page num, page_size, "select", params: page_params
      response.docs
    end

  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
ddr-models-2.4.12 lib/ddr/index/query_result.rb
ddr-models-2.4.11 lib/ddr/index/query_result.rb
ddr-models-2.4.10 lib/ddr/index/query_result.rb
ddr-models-2.4.9 lib/ddr/index/query_result.rb
ddr-models-2.4.8 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.17 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.16 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.15 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.14 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.13 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.12 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.11 lib/ddr/index/query_result.rb
ddr-models-2.4.7 lib/ddr/index/query_result.rb
ddr-models-2.4.6 lib/ddr/index/query_result.rb
ddr-models-2.4.5 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.10 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.9 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.8 lib/ddr/index/query_result.rb
ddr-models-3.0.0.beta.7 lib/ddr/index/query_result.rb
ddr-models-2.4.4 lib/ddr/index/query_result.rb