Class: MarkLogic::Queries::ValueQuery

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

Instance Method Summary collapse

Methods inherited from BaseQuery

#add_sub_query, #query_value

Constructor Details

#initialize(name, value, options = {}) ⇒ ValueQuery

Returns a new instance of ValueQuery.



4
5
6
7
8
9
10
11
# File 'lib/marklogic/queries/value_query.rb', line 4

def initialize(name, value, options = {})
  @name = name.to_s
  @value = value
  @value = value.to_s if value.is_a?(ObjectId)
  @options = options || {}
  @weight = @options.delete(:weight) || 1.0
  @options[:exact] = true if @options.length == 0
end

Instance Method Details

#optionsObject



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

def options
  opts = []
  @options.each do |k, v|
    dashed_key = k.to_s.gsub(/_/, '-')
    case k.to_s
    when "lang", "min_occurs", "max_occurs"
      opts << %Q{"#{dashed_key}=#{v}"}
    when /(case|diacritic|punctuation|whitespace)_sensitive/
      opts << (v == true ? %Q{"#{$1}-sensitive"} : %Q{"#{$1}-insensitive"})
    when "exact"
      opts << %Q{"#{dashed_key}"}
    when "stemmed", "wildcarded"
      opts << (v == true ? %Q{"#{dashed_key}"} : %Q{"un#{dashed_key}"})
    else
      opts << %Q{"#{v}"}
    end
  end

  opts
end

#options=(opts) ⇒ Object



13
14
15
# File 'lib/marklogic/queries/value_query.rb', line 13

def options=(opts)
  @options = opts
end

#to_xqyObject



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

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