Module: Moonstone::Racker::LocalClient

Defined in:
lib/moonstone/racker/client.rb

Instance Method Summary collapse

Instance Method Details

#details(id) ⇒ Object



32
33
34
35
36
# File 'lib/moonstone/racker/client.rb', line 32

def details(id)
  HTTParty.get("#{uri}/document.json", :query => {:id => id})
rescue Errno::ECONNREFUSED
  {}
end

#geo(location) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/moonstone/racker/client.rb', line 17

def geo(location)
  lat = location['lat'] || location['latitude'] || location['LAT'] || 
    location[:lat] || location[:latitude]
  lon = location['lon'] || location['long'] || location['LON'] ||
    location['longitude'] || location[:lon] || 
    location[:long] || location[:longitude]
  {'latitude' => lat, "longitude" => lon} if lat && lon
end

#index_infoObject



26
27
28
29
30
# File 'lib/moonstone/racker/client.rb', line 26

def index_info
  HTTParty.get("#{uri}/index_info.json")
rescue Errno::ECONNREFUSED
  {}
end

#search(topic, location, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/moonstone/racker/client.rb', line 5

def search(topic, location, options={})
  raise "Unable to use supplied location: #{location}" unless loc = geo(location)
  query = {:input => topic, :lat => loc['latitude'].to_s, :lon => loc['longitude'].to_s}
  r = HTTParty.get("#{uri}/search.json", :query => query)
  hash = {}
  r.each { |k,v| hash[k] = v }
  hash['location'] = loc
  hash
rescue Errno::ECONNREFUSED
  {}
end