Class: Ddr::Index::QueryClause

Inherits:
Object
  • Object
show all
Defined in:
lib/ddr/index/query_clause.rb

Constant Summary collapse

PRESENT =
"[* TO *]"
TERM =
"{!term f=%s}%s"
BEFORE_DAYS =
"[* TO NOW-%sDAYS]"

Class Method Summary collapse

Class Method Details

.absent(field) ⇒ Object



28
29
30
# File 'lib/ddr/index/query_clause.rb', line 28

def absent(field)
  negative field, PRESENT
end

.before(field, date_time) ⇒ Object



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

def before(field, date_time)
  value = "[* TO %s]" % Ddr::Utils.solr_date(date_time)
  build field, value
end

.before_days(field, days) ⇒ Object



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

def before_days(field, days)
  value = BEFORE_DAYS % days.to_i
  build field, value
end

.build(field, value) ⇒ Object

Standard Solr query, no escaping applied



10
11
12
# File 'lib/ddr/index/query_clause.rb', line 10

def build(field, value)
  [field, value].join(":")
end

.negative(field, value) ⇒ Object



20
21
22
# File 'lib/ddr/index/query_clause.rb', line 20

def negative(field, value)
  build "-#{field}", value
end

.or_values(field, *values) ⇒ Object



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

def or_values(field, *values)
  build field, QueryValue.or_values(*values)
end

.present(field) ⇒ Object



24
25
26
# File 'lib/ddr/index/query_clause.rb', line 24

def present(field)
  build field, PRESENT
end

.term(field, value) ⇒ Object



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

def term(field, value)
  TERM % [field, value.gsub(/"/, '\"')]
end

.unique_key(value) ⇒ Object Also known as: id, pid



14
15
16
# File 'lib/ddr/index/query_clause.rb', line 14

def unique_key(value)
  term(UniqueKeyField.instance, value)
end