Class: Ddr::Index::QueryResult
Constant Summary
collapse
- PAGE_SIZE =
1000
Instance Attribute Summary
#conn, #query
Instance Method Summary
collapse
#count, #initialize
Instance Method Details
#all ⇒ Object
44
45
46
|
# File 'lib/ddr/index/query_result.rb', line 44
def all
to_a
end
|
#docs ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/ddr/index/query_result.rb', line 36
def docs
Enumerator.new do |e|
each do |doc|
e << DocumentBuilder.build(doc)
end
end
end
|
#each(&block) ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/ddr/index/query_result.rb', line 8
def each(&block)
if params[:rows]
each_unpaginated(&block)
else
each_paginated(&block)
end
end
|
#each_paginated(&block) ⇒ Object
20
21
22
|
# File 'lib/ddr/index/query_result.rb', line 20
def each_paginated(&block)
pages.each { |pg| pg.each(&block) }
end
|
#each_pid(&block) ⇒ Object
32
33
34
|
# File 'lib/ddr/index/query_result.rb', line 32
def each_pid(&block)
pids.each(&block)
end
|
#each_unpaginated(&block) ⇒ Object
16
17
18
|
# File 'lib/ddr/index/query_result.rb', line 16
def each_unpaginated(&block)
conn.select(params).docs.each(&block)
end
|
#page(num) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/ddr/index/query_result.rb', line 62
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
|
#pages ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/ddr/index/query_result.rb', line 48
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
|
#pids ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/ddr/index/query_result.rb', line 24
def pids
Enumerator.new do |e|
each do |doc|
e << doc[Fields::PID]
end
end
end
|