class MarkLogic::Queries::NearQuery

Public Class Methods

new(queries, distance = 10, distance_weight = 1.0, options = {}) click to toggle source
# File lib/marklogic/queries/near_query.rb, line 4
def initialize(queries, distance = 10, distance_weight = 1.0, options = {})
  @queries = queries
  @distance = distance
  @distance_weight = distance_weight
  @ordered = options.delete(:ordered)
end

Public Instance Methods

to_json() click to toggle source
# File lib/marklogic/queries/near_query.rb, line 11
def to_json
  json = {
    "near-query" => {
      "queries" => @queries.map { |q| q.to_json }
    }
  }

  json["near-query"]["queries"].push({ "distance" => @distance }) if @distance
  json["near-query"]["queries"].push({ "distance-weight" => @distance_weight }) if @distance_weight
  json["near-query"]["queries"].push({ "ordered" => @ordered })
  json
end
to_xqy() click to toggle source
# File lib/marklogic/queries/near_query.rb, line 24
def to_xqy
  queries = @queries.map { |q| q.to_xqy }.join(',')
  ordered = (@ordered == true ? %Q{"ordered"} : %Q{"unordered"}) if !@ordered.nil?
  %Q{cts:near-query((#{queries}),#{@distance},(#{ordered}),#{@distance_weight})}
end