Hai everybody,

What I have to do if I need to search in my models to get result in
accenting order of  distance from a given location, provided I have a
model which  contains lat ad lng details and it is prperly associated
with other model

I use geo code to get the lat and lng details ( include
GeoKit::Geocoders )

I could use the following query:

locations = Place.find(:all,
        :limit=>30,
        :origin => [[email protected], @location.lng],
        :conditions => "distance < 1000",
        :order=>'distance DESC')

But when it comes to JOIN with other models and apply conditions on
them I can only get the list of place object. I need to get the fields
from the other models too along with the fields in the Place model.


How can I accomplish this using Thinking Sphinx


Please Help me !


On Jul 28, 7:30 pm, Pat Allan <[email protected]> wrote:
> Hi Aninda
>
> Firstly, you'll need to ensure theassociationis referenced somewhere  
> in your index setup:
>    has location(:id), :as => :location_id
>
> And then you can add custom SQL snippets for generating lat and lng in  
> radians:
>    has 'RADIANS(location.lat)', :as => :lat, :type => :float
>    has 'RADIANS(location.lng)', :as => :lng, :type => :float
>
> Cheers
>
> --
> Pat
>
> On 28/07/2009, at 2:52 PM, Aninda wrote:
>
>
>
> > Hi,
> >  I also have thegeocodeattributesstored in anassociationmodel,
> > but they are stored in decimal degrees:
> > How would I then convert theseattributesinto radians for ts?
> >  has location(:lat), :as => :latit
> >  has location(:lng), :as => :longit
>
> > Thanks!
>
> > On Jul 24, 1:57 pm, Pat Allan <[email protected]> wrote:
> >> Hi John
>
> >> What you're doing should work... how are you searching on your
> >> CoffeeShop model? And are the columns in your locations table storing
> >> lat and lng in radians?
>
> >> --
> >> Pat
>
> >> On 23/07/2009, at 5:51 PM, DB_John wrote:
>
> >>> Can thegeocodeattributesof a model be set toattributesfrom an
> >>> associated model?
>
> >>> I have a CoffeeShop model that stores its location information in a
> >>> Location model.  I've been trying different versions of the  
> >>> following
> >>> to no success:
>
> >>>  define_index do
> >>>    has location(:lat), :as => :latit
> >>>    has location(:lng), :as => :longit
>
> >>>    set_property :latitude_attr   => :latit
> >>>    set_property :longitude_attr  => :longit
> >>>  end
>
> >>> Do I need to explicitly add thoselat/lngcolumns to my CoffeeShop
> >>> table?
>
> >>> Thanks,
> >>> John

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to