Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:17:27+00:00 2026-05-22T22:17:27+00:00

I have successfully got Thinking Sphinx working with Geolocation on an associated model. Happy

  • 0

I have successfully got Thinking Sphinx working with Geolocation on an associated model. Happy days!

But I now need it to show the right associated record on a Google map.

The scenario is a Company with has_many offices. Offices have got the lng,lat values. I am searching on the Company and associating the offices to it.

E.g.

  define_index do

 indexes :name, :sortable => true
 indexes offices(:city), :as => :city
 indexes offices(:postal_code), :as => :postal_code

 has "RADIANS(offices.lat)", :as => :lat,  :type => :float
 has "RADIANS(offices.lng)", :as => :lng,  :type => :float

 has created_at
 has updated_at

 set_property :latitude_attr  => 'lat'
 set_property :longitude_attr => 'lng'
 set_property :field_weights  => { 'name'        => 10,
                                  'service_name' => 9,
                                  'city'    => 8 }

 end

Searching for x company in y location / postcode works perfectly, showing the correct companies that have got offices in the desired location within the @geodist radius.

E.g.

{:geo=>[0.9283660690549609, -0.050527407508941975], :sort_mode=>:expr, :sort_by=>"@weight * @weight / @geodist", :with=>{"@geodist"=>0.0..120700.8}, :conditions=>{:service_name=>"Business strategies"}, :page=>1, :per_page=>12, :star=>true}

The resulting records are company object, not the offices, which is fine for the list view but I want to show icons on a google map of the relevant associated office.

What is the best way to find the relevant associated office record to show within the radius bounds?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:17:28+00:00Added an answer on May 22, 2026 at 10:17 pm

    Sphinx only reliably handles single-value float attributes – and it has no concept of paired lat/lng values. This means that you can’t have a solid search across objects with more than one lat/lng pair.

    The best workaround is to actually search on Office instead – and perhaps pull in each office’s company information:

    define_index do
      indexes company.name, :as => :name, :sortable => true
      indexes city, postal_code
    
      has "RADIANS(offices.lat)", :as => :lat,  :type => :float
      has "RADIANS(offices.lng)", :as => :lng,  :type => :float
      has company.created_at, :as => :created_at
      has company.updated_at, :as => :updated_at
      has company_id
    
      set_property :field_weights  => {
        'name'         => 10,
        'service_name' => 9,
        'city'         => 8
      }
    end
    

    And then when searching, you can group by company_id to ensure only one result for any company (if that’s what you’d prefer):

    Office.search 'foo',
      :geo            => [lat, lng],
      :with           => {'@geodist' => 0.0..120700.8}
      :group_function => :attr
      :group_by       => 'company_id'
    

    If it’s important as to which Office gets returned for a given company_id, then you’ll probably want to use the :group_clause option as well. The docs cover this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using CURL, but I have successfully got it to submit ordinary
What I have now (which successfully loads the plug-in) is this: Assembly myDLL =
I have a script that successfully encrypts a credit card. I need it to
I have been using Hibernate very successfully, but today I noticed a bizarre phenomenon
Basically, i have purchased HTC Hero (Android sdk 1.5) , but i just got
i have a input tag which is non editable, but some times i need
I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008)
I have a Rails app that I have successfully tested with Mongrel and Webkit.
I believe that I have successfully impersonated my own user account while running an
I'm familiar with the LAMP stack and over the years have successfully deployed a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.