Class: MarkLogic::Queries::RangeQuery

Inherits:
BaseQuery
  • Object
show all
Defined in:
lib/marklogic/queries/range_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseQuery

#add_sub_query, #query_value

Constructor Details

#initialize(name, operator, range_type, value, options = {}) ⇒ RangeQuery

Returns a new instance of RangeQuery.


7
8
9
10
11
12
13
14
# File 'lib/marklogic/queries/range_query.rb', line 7

def initialize(name, operator, range_type, value, options = {})
  @name = name.to_s
  @operator = operator.to_s.upcase
  @range_type = range_type
  @value = value
  @options = options || {}
  @weight = @options.delete(:weight) || 1.0
end

Instance Attribute Details

#nameObject

Returns the value of attribute name


5
6
7
# File 'lib/marklogic/queries/range_query.rb', line 5

def name
  @name
end

#range_typeObject

Returns the value of attribute range_type


5
6
7
# File 'lib/marklogic/queries/range_query.rb', line 5

def range_type
  @range_type
end

Instance Method Details

#operatorObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/marklogic/queries/range_query.rb', line 20

def operator
  case @operator
    when "LT"
      "<"
    when "LE"
      "<="
    when "GT"
      ">"
    when "GE"
      ">="
    when "EQ"
      "="
    when "NE"
      "!="
    else
      @operator
  end
end

#operator=(op) ⇒ Object


16
17
18
# File 'lib/marklogic/queries/range_query.rb', line 16

def operator=(op)
  @operator = op
end

#optionsObject


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/marklogic/queries/range_query.rb', line 43

def options
  opts = []
  @options.each do |k, v|
    case k.to_s
    when "collation", "min_occurs", "max_occurs", "score_function", "slope_factor"
      opts << %Q{"#{k.to_s.gsub(/_/, '-')}=#{v}"}
    when "cached"
      opts << (v == true ? %Q{"cached"} : %Q{"uncached"})
    when "synonym"
      opts << %Q{"#{k}"}
    else
      opts << %Q{"#{v}"}
    end
  end

  opts
end

#options=(opts) ⇒ Object


39
40
41
# File 'lib/marklogic/queries/range_query.rb', line 39

def options=(opts)
  @options = opts
end

#to_xqyObject


61
62
63
64
# File 'lib/marklogic/queries/range_query.rb', line 61

def to_xqy
  value = query_value(@value, @range_type)
  %Q{cts:json-property-range-query("#{@name}","#{operator}",(#{value}),(#{options.join(',')}),#{@weight})}
end