Sha256: 294ff78310134148fd622dd1841bde91ecd4826933269a2d3d94ad78852992c4
Contents?: true
Size: 1.46 KB
Versions: 17
Compression:
Stored size: 1.46 KB
Contents
module Ddr::Index class QueryResult < AbstractQueryResult extend Deprecation 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 Deprecation.warn(QueryResult, "`pids` is deprecated; use `ids` instead.") ids end def ids Enumerator.new do |e| each do |doc| e << doc[Fields::ID] end end end def each_pid(&block) Deprecation.warn(QueryResult, "`each_pid` is deprecated; use `each_id` instead.") each_id(&block) end def each_id(&block) ids.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
17 entries across 17 versions & 1 rubygems