Class: MarkLogic::Queries::GeospatialQuery

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

Instance Method Summary collapse

Methods inherited from BaseQuery

#add_sub_query, #query_value

Constructor Details

#initialize(name, regions, options = {}) ⇒ GeospatialQuery

Returns a new instance of GeospatialQuery.



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

def initialize(name, regions, options = {})
  @name = name
  @regions = regions
  @options = options || {}
  @weight = @options.delete(:weight) || 1.0
end

Instance Method Details

#optionsObject



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

def options
  opts = []
  @options.each do |k, v|
    dashed_key = k.to_s.gsub(/_/, '-')
    case k.to_s
    when "coordinate_system", "units", "type", "score_function", "slope_factor"
      opts << %Q{"#{dashed_key}=#{v}"}
    when /(boundaries)_included/
      opts << (v == true ? %Q{"#{$1}-included"} : %Q{"#{$1}-excluded"})
    when /([a-z\-]+_excluded)/
      opts << %Q{"#{dashed_key}"}
    when "cached"
      opts << (v == true ? %Q{"cached"} : %Q{"uncached"})
    when "zero", "synonym"
      opts << %Q{"#{dashed_key}"}
    # else
    #   opts << %Q{"#{v}"}
    end
  end

  opts
end

#options=(opts) ⇒ Object



11
12
13
# File 'lib/marklogic/queries/geospatial_query.rb', line 11

def options=(opts)
  @options = opts
end

#to_xqyObject



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

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