class Rawscsi::Query::Compound
Attributes
query_hash[R]
Public Class Methods
new(query_hash)
click to toggle source
# File lib/rawscsi/query/compound.rb, line 7 def initialize(query_hash) @query_hash = query_hash end
Public Instance Methods
build()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 11 def build [ query, distance, qoptions, date, sort, start, limit, fields, "q.parser=structured" ].compact.join("&") end
Private Instance Methods
FRC3339(date_str)
click to toggle source
# File lib/rawscsi/query/compound.rb, line 39 def FRC3339(date_str) return date_str if /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ =~ date_str date_str.gsub(/\d{4}-\d{2}-\d{2}/) do |dt| "#{dt}T00:00:00Z" end end
date()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 30 def date return nil unless date_hash = query_hash[:date] output_str = "fq=" date_hash.each do |k,v| output_str << "#{k}:#{FRC3339(v)}" end encode(output_str) end
distance()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 51 def distance return nil unless location = query_hash[:location] "expr.distance=haversin(#{location[:latitude]},#{location[:longitude]},location.latitude,location.longitude)" end
fields()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 71 def fields return nil unless fields_array = query_hash[:fields] output = [] fields_array.each do |field_sym| output << field_sym.to_s end "return=" + output.join(",") end
limit()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 66 def limit return nil unless query_hash[:limit] "size=#{query_hash[:limit]}" end
qoptions()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 56 def qoptions return nil unless weights = query_hash[:weights] "q.options=#{CGI.escape(weights)}" end
query()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 26 def query "q=" + Rawscsi::Query::Stringifier.new(query_hash[:q]).build end
sort()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 46 def sort return nil unless query_hash[:sort] encode("sort=#{query_hash[:sort]}") end
start()
click to toggle source
# File lib/rawscsi/query/compound.rb, line 61 def start return nil unless query_hash[:start] "start=#{query_hash[:start]}" end