Class: Ddr::Index::Query

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Query.



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

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

Instance Method Details

#==(other) ⇒ Object



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

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(&block) ⇒ Object



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

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

#csvObject



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

def csv
  CSVQueryResult.new(self)
end

#each_pid(&block) ⇒ Object



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

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

#filter_clausesObject



53
54
55
# File 'lib/ddr/index/query.rb', line 53

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

#inspectObject



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

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

#pidsObject



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

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

#query_paramsObject



57
58
59
# File 'lib/ddr/index/query.rb', line 57

def query_params
  QueryParams.new(self)
end

#resultObject



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

def result
  QueryResult.new(self)
end

#to_sObject



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

def to_s
  URI.encode_www_form(params)
end