Class: Ddr::Index::QueryResult

Inherits:
AbstractQueryResult show all
Extended by:
Deprecation
Defined in:
lib/ddr/index/query_result.rb

Constant Summary collapse

PAGE_SIZE =
1000

Instance Attribute Summary

Attributes inherited from AbstractQueryResult

#conn, #query

Instance Method Summary collapse

Methods inherited from AbstractQueryResult

#count, #initialize

Constructor Details

This class inherits a constructor from Ddr::Index::AbstractQueryResult

Instance Method Details

#allObject



55
56
57
# File 'lib/ddr/index/query_result.rb', line 55

def all
  to_a
end

#docsObject



47
48
49
50
51
52
53
# File 'lib/ddr/index/query_result.rb', line 47

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

#each(&block) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/ddr/index/query_result.rb', line 9

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

#each_id(&block) ⇒ Object



43
44
45
# File 'lib/ddr/index/query_result.rb', line 43

def each_id(&block)
  ids.each(&block)
end

#each_paginated(&block) ⇒ Object



21
22
23
# File 'lib/ddr/index/query_result.rb', line 21

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

#each_pid(&block) ⇒ Object



38
39
40
41
# File 'lib/ddr/index/query_result.rb', line 38

def each_pid(&block)
  Deprecation.warn(QueryResult, "`each_pid` is deprecated; use `each_id` instead.")
  each_id(&block)
end

#each_unpaginated(&block) ⇒ Object



17
18
19
# File 'lib/ddr/index/query_result.rb', line 17

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

#idsObject



30
31
32
33
34
35
36
# File 'lib/ddr/index/query_result.rb', line 30

def ids
  Enumerator.new do |e|
    each do |doc|
      e << doc[Fields::ID]
    end
  end
end

#page(num) ⇒ Object



73
74
75
76
77
78
# File 'lib/ddr/index/query_result.rb', line 73

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

#pagesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ddr/index/query_result.rb', line 59

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

#pidsObject



25
26
27
28
# File 'lib/ddr/index/query_result.rb', line 25

def pids
  Deprecation.warn(QueryResult, "`pids` is deprecated; use `ids` instead.")
  ids
end