Created
June 28, 2011 14:13
-
-
Save karmi/1051213 to your computer and use it in GitHub Desktop.
Revisions
-
karmi revised this gist
Aug 1, 2012 . 1 changed file with 29 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,47 @@ require 'tire' require 'active_support/core_ext/numeric' require 'active_support/core_ext/time/zones' # Tire.configure { logger STDERR, level: 'debug' } class Time; DATE_FORMATS.update lucene: "%Y-%m-%dT%H:%M"; end Tire.index 'venues' do delete # 1) Create the index with proper mapping for the `location` property create mappings: { venue: { properties: { location: { type: 'geo_point' }, updated_at: { type: 'date', format: 'date_hour_minute' } } } } # 2) Store some example documents of the `venue` type store type: 'venue', name: 'One', location: [40.1, -70.1], updated_at: 3.hours.ago.utc.to_s(:lucene) store type: 'venue', name: 'Two', location: [40.2, -70.2], updated_at: 2.hours.ago.utc.to_s(:lucene) store type: 'venue', name: 'Three', location: [50, 15], updated_at: 1.hour .ago.utc.to_s(:lucene) refresh end s = Tire.search 'venues' do # 3) Search based on geo distance filter 'geo_distance', distance: '100km', location: [40, -70] # 4) Sort by distance to origin # sort { by :_geo_distance, location: [40, -70] } # 5) Sort by `updated_at` property sort { by :updated_at, 'desc' } end puts s.to_curl, '-'*80 s.results.each do |d| puts "* #{d.name} | location: #{d.location}, updated_at: #{d.updated_at}" end -
karmi created this gist
Jun 28, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ require 'rubygems' require 'tire' Tire.index 'venues' do delete # 1) Create the index with proper mapping for the `location` property create :mappings => { :venue => { :properties => { :location => { :type => 'geo_point' } } } } # 2) Store some example documents of the `venue` type store :venue, :name => 'One', :location => [40.01, -70.01] store :venue, :name => 'Two', :location => [50, 15] refresh end s = Tire.search 'venues' do # 3) Search based on geo distance filter 'geo_distance', :distance => '12km', :location => [40, -70] end s.results.each do |document| p document end