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

#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



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

def all
  to_a
end

#docsObject



53
54
55
56
57
58
59
# File 'lib/ddr/index/query_result.rb', line 53

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



49
50
51
# File 'lib/ddr/index/query_result.rb', line 49

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



41
42
43
44
45
46
47
# File 'lib/ddr/index/query_result.rb', line 41

def each_pid(&block)
  Deprecation.warn(QueryResult,
                   "`each_pid` is deprecated; use `each_id` instead." \
                   " (called from #{caller.first})"
                  )
  each_id(&block)
end

#each_unpaginated(&block) ⇒ Object



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

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

#facet_fieldsObject



69
70
71
72
73
74
# File 'lib/ddr/index/query_result.rb', line 69

def facet_fields
  response = Connection.select(params, rows: 0)
  response.facet_fields.each_with_object({}) do |(field, values), memo|
    memo[field] = Hash[*values]
  end
end

#idsObject



33
34
35
36
37
38
39
# File 'lib/ddr/index/query_result.rb', line 33

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

#objectsObject



61
62
63
64
65
66
67
# File 'lib/ddr/index/query_result.rb', line 61

def objects
  Enumerator.new do |e|
    each_id do |id|
      e << ActiveFedora::Base.find(id)
    end
  end
end

#page(num) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/ddr/index/query_result.rb', line 94

def page(num)
  data = params.dup
  page_size = data.delete(:rows) || PAGE_SIZE
  opts = { method: :post, data: data }
  response = Connection.page(num, page_size, 'select', opts)
  response.docs
end

#pagesObject



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ddr/index/query_result.rb', line 80

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
29
30
31
# File 'lib/ddr/index/query_result.rb', line 25

def pids
  Deprecation.warn(QueryResult,
                   "`pids` is deprecated; use `ids` instead." \
                   " (called from #{caller.first})"
                  )
  ids
end