Skip to content

Instantly share code, notes, and snippets.

@hubertlepicki
Created July 16, 2010 14:12
Show Gist options
  • Save hubertlepicki/478413 to your computer and use it in GitHub Desktop.
Save hubertlepicki/478413 to your computer and use it in GitHub Desktop.
require 'riddle'
require 'riddle/0.9.9'
companies = %w(AmberBit Google HP)
client = Riddle::Client.new "localhost", 5000
client.match_mode = :extended
client.sort_mode = :extended
client.sort_by = "@geodist ASC"
puts "What's your latitude: "
lat = gets.to_f * Math::PI / 180.0
puts "What's your longitude: "
lng = gets.to_f * Math::PI / 180.0
puts "Top IT companies near you, ordered by distance: "
client.set_anchor "lat", lat, "lng", lng
client.query("", "pois")[:matches].each do |record|
puts companies[record[:doc]-1]
end
<?xml version="1.0" encoding="utf-8"?>
<sphinx:docset>
<sphinx:schema>
<sphinx:field name="name"/>
<sphinx:attr name="lat" type="float"/>
<sphinx:attr name="lng" type="float"/>
</sphinx:schema>
<sphinx:document id="1">
<name><![CDATA[AmberBit HQ]]></name>
<lat>0.927042715037538</lat>
<lng>0.403538937710426</lng>
</sphinx:document>
<sphinx:document id="2">
<name><![CDATA[Google HQ]]></name>
<lat>0.656188367092825</lat>
<lng>-2.13395902872886</lng>
</sphinx:document>
<sphinx:document id="3">
<name><![CDATA[Hewlett-Packard HQ]]></name>
<lat>0.657782603191474</lat>
<lng>-2.13395902872886</lng>
</sphinx:document>
</sphinx:docset>
source dummy
{
type = xmlpipe2
xmlpipe_command = bash -c "cat pois.xml"
}
index pois
{
source = dummy
path = tmp/places
docinfo = extern
mlock = 0
charset_type = utf-8
html_strip = 0
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 127.0.0.1:5000
log = tmp/searchd.log
query_log = tmp/query.log
read_timeout = 1
client_timeout = 1
max_children = 60
pid_file = tmp/searchd.pid
max_matches = 10000000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
mva_updates_pool = 1M
max_packet_size = 8M
max_filters = 256
max_filter_values = 4096
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment