Class: Ddr::Index::Query

Inherits:
Object
  • Object
show all
Extended by:
Deprecation, Forwardable
Defined in:
lib/ddr/index/query.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args, &block) ⇒ Query

Returns a new instance of Query.



25
26
27
28
29
30
# File 'lib/ddr/index/query.rb', line 25

def initialize(**args, &block)
  super(**args)
  if block_given?
    build(&block)
  end
end

Class Method Details

.build(*args, &block) ⇒ Object



19
20
21
22
23
# File 'lib/ddr/index/query.rb', line 19

def self.build(*args, &block)
  new.tap do |query|
    query.build(*args, &block)
  end
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  other.instance_of?(self.class) &&
    other.q == self.q &&
    other.fields == self.fields &&
    other.filters == self.filters &&
    other.rows == self.rows &&
    other.sort == self.sort
end

#build(*args, &block) ⇒ Object



67
68
69
70
# File 'lib/ddr/index/query.rb', line 67

def build(*args, &block)
  QueryBuilder.new(self, *args, &block)
  self
end

#csvObject



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

def csv
  CSVQueryResult.new(self)
end

#each_pid(&block) ⇒ Object



46
47
48
49
# File 'lib/ddr/index/query.rb', line 46

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

#filter_clausesObject



59
60
61
# File 'lib/ddr/index/query.rb', line 59

def filter_clauses
  filters.map(&:clauses).flatten
end

#inspectObject



32
33
34
35
# File 'lib/ddr/index/query.rb', line 32

def inspect
  "#<#{self.class.name} q=#{q.inspect}, filters=#{filters.inspect}," \
  " sort=#{sort.inspect}, rows=#{rows.inspect}, fields=#{fields.inspect}>"
end

#pidsObject



41
42
43
44
# File 'lib/ddr/index/query.rb', line 41

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

#query_paramsObject



63
64
65
# File 'lib/ddr/index/query.rb', line 63

def query_params
  QueryParams.new(self)
end

#resultObject



51
52
53
# File 'lib/ddr/index/query.rb', line 51

def result
  QueryResult.new(self)
end

#to_sObject



37
38
39
# File 'lib/ddr/index/query.rb', line 37

def to_s
  URI.encode_www_form(params)
end