Oky Let me explain it...
Please go through the models given below
*class* Place < ActiveRecord::Base
*acts_as_mappable* # its a
mappable object,we keep lat and lng in this table
*has_many* :books, :through => :books_places
*has_many* :books_places, :dependent => :destroy
*end*
*class* Book < ActiveRecord::Base # this model has so may associations
to other models along with many_to_many associations with place model
acts_as_rateable
* belongs_to* :category
* belongs_to* :publisher
* has_one* :movie ,:dependent => :destroy
* has_many* :comments,:dependent => :destroy
*has_many* :places, :through => :books_places
* has_many* :books_places, :dependent => :destroy
*end*
*class* BooksPlace < ActiveRecord::Base
*belongs_to* :place
*belongs_to* :book
*end*
What I need is, Implement a advanced search form in which user may enter any
*place* he prefer, *book title *(this field is in Book model), *category* (a
field in category model) or a publisher name (a field in publisher model).
When a user submit form with a place given along with some other filters
like, book title or publisher name etc. we have to search in accenting order
of the distance from the given place and we must also consider the
conditions (book name,publisher name or category if given)
*Thanks *
2009/7/30 Pat Allan <[email protected]>
>
> We're going to need more information before we can offer much of a
> solution.
>
> Where are your lat/lng columns? What are the other fields you want in
> different models?
>
> --
> Pat
>
> On 29/07/2009, at 9:39 AM, BR!j!TH wrote:
>
> >
> > 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
> >
> > >
>
>
> >
>
--
"Dream is not what you see in sleep
is the thing which does not let you sleep"
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---