Location.search :geo => [33.89 * Math::PI / 180, -83.95 * Math::PI / 180], :with => {:geodist => 0.0..200_000.0}, :order => "geodist ASC"
Sphinx Query (338.5ms) SELECT GEODIST(0.5914920835008783, -1.4652039070492398, latitude, longitude) AS geodist, * FROM `location_core` WHERE `geodist` BETWEEN 0.0 AND 200000.0 AND `sphinx_deleted` = 0 ORDER BY `geodist` ASC LIMIT 0, 20
Sphinx Found 983 results
Location Load (0.5ms) SELECT `locations`.* FROM `locations` WHERE `locations`.`id` IN (12828, 12848, 12882, 12851, 12852, 12853, 12854, 12855, 12859, 12830, 12856, 12857, 12822, 12834, 12836, 12838, 12898, 12899, 12900, 12901)
=> [#<Location id: 12828, zipcode: "30017", city: "Grayson", state: "GA", latitude: 33.89, longitude: -83.95, created_at: nil, updated_at: nil>, #<Location id: 12848, zipcode: "30039", city: "Snellville", state: "GA", latitude: 33.85, longitude: -84.0, created_at: nil, updated_at: nil>, #<Location id: 12882, zipcode: "30078", city: "Snellville", state: "GA", latitude: 33.85, longitude: -84.0, created_at: nil, updated_at: nil>, #<Location id: 12851, zipcode: "30042", city: "Lawrenceville", state: "GA", latitude: 33.94, longitude: -83.99, created_at: nil, updated_at: nil>, #<Location id: 12852, zipcode: "30043", city: "Lawrenceville", state: "GA", latitude: 33.94, longitude: -83.99, created_at: nil, updated_at: nil>, #<Location id: 12853, zipcode: "30044", city: "Lawrenceville", state: "GA", latitude: 33.94, longitude: -83.99, created_at: nil, updated_at: nil>, #<Location id: 12854, zipcode: "30045", city: "Lawrenceville", state: "GA", latitude: 33.94, longitude: -83.99, created_at: nil, updated_at: nil>, #<Location id: 12855, zipcode: "30046", city: "Lawrenceville", state: "GA", latitude: 33.94, longitude: -83.99, created_at: nil, updated_at: nil>, #<Location id: 12859, zipcode: "30052", city: "Loganville", state: "GA", latitude: 33.83, longitude: -83.89, created_at: nil, updated_at: nil>, #<Location id: 12830, zipcode: "30019", city: "Dacula", state: "GA", latitude: 33.98, longitude: -83.88, created_at: nil, updated_at: nil>, #<Location id: 12856, zipcode: "30047", city: "Lilburn", state: "GA", latitude: 33.88, longitude: -84.13, created_at: nil, updated_at: nil>, #<Location id: 12857, zipcode: "30048", city: "Lilburn", state: "GA", latitude: 33.88, longitude: -84.13, created_at: nil, updated_at: nil>, #<Location id: 12822, zipcode: "30011", city: "Auburn", state: "GA", latitude: 34.01, longitude: -83.83, created_at: nil, updated_at: nil>, #<Location id: 12834, zipcode: "30024", city: "Suwanee", state: "GA", latitude: 34.05, longitude: -84.07, created_at: nil, updated_at: nil>, #<Location id: 12836, zipcode: "30026", city: "North Metro", state: "GA", latitude: 34.0, longitude: -84.15, created_at: nil, updated_at: nil>, #<Location id: 12838, zipcode: "30029", city: "North Metro", state: "GA", latitude: 34.0, longitude: -84.15, created_at: nil, updated_at: nil>, #<Location id: 12898, zipcode: "30095", city: "Duluth", state: "GA", latitude: 34.0, longitude: -84.15, created_at: nil, updated_at: nil>, #<Location id: 12899, zipcode: "30096", city: "Duluth", state: "GA", latitude: 34.0, longitude: -84.15, created_at: nil, updated_at: nil>, #<Location id: 12900, zipcode: "30097", city: "Duluth", state: "GA", latitude: 34.0, longitude: -84.15, created_at: nil, updated_at: nil>, #<Location id: 12901, zipcode: "30098", city: "Duluth", state: "GA", latitude: 34.0, longitude: -84.15, created_at: nil, updated_at: nil>]
user = User.first
User Load (0.3ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1
=> #<User id: 1, email: "ad...@admin.com", password_digest: "$2a$10$OuN0/fqWzy4ZTyIf4y94teIdnndAqwS.1V5zxgO9X7wW...", zip_code: "30052", birthday: "1986-08-25", name: nil, username: "admin", gender: "Male", ethnicity: nil, sexuality: "Straight", career: nil, education: nil, religion: nil, politics: nil, children: nil, height: nil, user_smoke: nil, user_drink: nil, about_me: nil, inches: nil, feet: nil, created_at: "2014-01-16 14:17:36", updated_at: "2014-01-16 14:17:36", auth_token: "8Zwh3HF6WnA8wthFZirkQw", password_reset_token: nil, password_reset_sent_at: nil, admin: nil, role: "admin", roles_mask: nil, age: nil, default_photo_id: nil, location_id: nil, time_zone: nil>
2.0.0-p353 :004 > user.location
(15.4ms) SELECT COUNT(*) FROM `locations` WHERE (zipcode = '30052')
Location Load (6.8ms) SELECT `locations`.* FROM `locations` WHERE (zipcode = '30052') ORDER BY `locations`.`id` ASC LIMIT 1
=> #<Location id: 12859, zipcode: "30052", city: "Loganville", state: "GA", latitude: 33.83, longitude: -83.89, created_at: nil, updated_at: nil>
class DistanceController < ApplicationController
def search
@latitude = params[:latitude].to_f * Math::PI / 180
@longitude = params[:longitude].to_f * Math::PI / 180
@users = Location.search :geo => [@latitude * Math::PI / 180, @longitude * Math::PI / 180], :with => {:geodist => 0.0..200_000.0}, :order => "geodist ASC"
end
def users
@users = User.all
end
def index
@users = User.all
end
end
ThinkingSphinx::Index.define :location, :with => :active_record do
indexes city
has "RADIANS(locations.latitude)", :as => :latitude, :type => :float
has "RADIANS(locations.longitude)", :as => :longitude, :type => :float
end
ThinkingSphinx::Index.define :user, :with => :active_record do
indexes name, :as => :user, :sortable => true
indexes zip_code
has created_at, updated_at
has location.id, :as => :location_id
end
<%= form_tag searches_path, method: :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= button_tag "Search", name: nil %>
</p>
<% end %>
:with => {:geodist => 0.0..200_000.0},
Location.search :geo => [33.83 * Math::PI / 180, -83.89 * Math::PI / 180], :with => {:geodist => 0.0..200_000.0}, :order => "geodist ASC"
Sphinx Query (27.0ms) SELECT GEODIST(0.5904448859496816, -1.464156709498043, latitude, longitude) AS geodist, * FROM `location_core` WHERE `geodist` BETWEEN 0.0 AND 200000.0 AND `sphinx_deleted` = 0 ORDER BY `geodist` ASC LIMIT 0, 20
Sphinx Found 979 results
Location Load (0.6ms) SELECT `locations`.* FROM `locations` WHERE `locations`.`id` IN (12859, 12828, 12848, 12882, 12851, 12852, 12853, 12854, 12855, 12829, 12830, 13285, 13286, 12822, 13261, 12823, 12824, 12897, 12856, 12857)
Pat
To unsubscribe from this group and stop receiving emails from it, send an email to thinking-sphinx+unsubscribe@googlegroups.com.
To post to this group, send email to thinking-sphinx@googlegroups.com.
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the Google Groups "Thinking Sphinx" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/thinking-sphinx/m6H_24ZSqvs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to thinking-sphinx+unsubscribe@googlegroups.com.
To post to this group, send email to thinking-sphinx@googlegroups.com.