Class: MarkLogic::Queries::WordQuery

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

Instance Method Summary collapse

Methods inherited from BaseQuery

#add_sub_query, #query_value

Constructor Details

#initialize(values, options = {}) ⇒ WordQuery

Returns a new instance of WordQuery.



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

def initialize(values, options = {})
  @values = values
  @options = options || {}
  @weight = @options.delete(:weight) || 1.0
  @options[:exact] = true if @options.length == 0
end

Instance Method Details

#optionsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/marklogic/queries/word_query.rb', line 11

def options
  opts = []
  @options.each do |k, v|
    dashed_key = k.to_s.gsub(/_/, '-')
    case k.to_s
    when "lang", "distance_weight", "min_occurs", "max_occurs", "lexicon_expand"
      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

#to_xqyObject



32
33
34
35
# File 'lib/marklogic/queries/word_query.rb', line 32

def to_xqy
  values = query_value(@values)
  %Q{cts:word-query((#{values}),(#{options.join(',')}),#{@weight})}
end