Created
February 6, 2012 12:19
-
-
Save vhyza/1751827 to your computer and use it in GitHub Desktop.
Tire issue #228
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tire' | |
Tire.index 'users_tire_issue' do | |
delete | |
create mappings: { | |
user: { | |
properties: { | |
email: { type: 'string' }, | |
names: { type: 'string', analyzer: 'snowball' }, | |
medical_conditions: { | |
properties: { | |
condition: { type: 'string' }, | |
notes: { type: 'string' } | |
} | |
}, | |
addresses: { | |
properties: { | |
lat_lon: { type: 'geo_point' } | |
} | |
} | |
} | |
} | |
} | |
store({ _type: 'user', email: 'email@example.com', names: ["chance dinkins","abraham lincoln"], addresses: [{ lat_lon: '34.078567,-81.173366' }] }) | |
store({ _type: 'user', email: 'another_email@example.com', names: ["chance dinkins","abraham lincoln"], addresses: [{ lat_lon: '34,-81.173366' }] }) | |
store({ _type: 'user', email: 'another_another_email@example.com', names: ["chance dinkins","chancey dinkins"], addresses: [{ lat_lon: '34.078567,-81' }] }) | |
store({ _type: 'user', email: 'nothing@example.com', names: 'nothing', addresses: [{ lat_lon: '34.078567,-81' }] }) | |
refresh | |
end | |
class AgentUserSearch | |
include Tire::Model::Search | |
def name | |
'chance' | |
end | |
def lat_lon | |
"34.078567,-81.173366" | |
end | |
def search_users | |
me = self | |
search = Tire.search 'users_tire_issue' do |search| | |
search.query do |query| | |
query.string "names: #{me.name}" unless me.name.empty? | |
end | |
search.filter :geo_distance, distance: "10mi", 'addresses.lat_lon' => me.lat_lon | |
end | |
search | |
end | |
end | |
search = AgentUserSearch.new.search_users | |
search.results.each do |r| | |
puts "email: #{r.email}" | |
puts "addresses: #{r.addresses.first.lat_lon}" | |
puts "-----" | |
end | |
p search.to_curl | |
p search.results.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment