Pat,
   Everything you suggested was extremely useful.  For the edification of
those who come across this later, I a bit of the following.  I added 2
Sphinx scopes (and I put them both in the Address model and the Business
model):
  sphinx_scope(:website_only) {
    {:with => {:website_only => true}}
  }
  sphinx_scope(:physical) {
    {:with => {:website_only => false}}
  }

I also added this line to the Address model:
    has website_only, :as => :website_only
and this line to the Business model:
    has addresses.website_only, :as => :website_only

Adding those lines allowed me to do this in the search_controller.rb:
      @map_businesses = Search.execute(Address, params[:search][:query],
                                        :page => params[:page], :miles =>
params[:miles].to_i,
                                        :location => @location).physical
      @web_businesses = Business.search( params[:search][:query]
).website_only

Also, if anyone else caught my issue with how to search the Business tags
from acts_as_taggable_on, it should look like this from the Address model:
    indexes business.businesstypes.name, :as => :businesstypes
    indexes business.region.name, :as => :region
and this from the Business model:
  acts_as_taggable_on   :businesstypes
  acts_as_taggable_on   :region

  define_index do
    ...
    indexes businesstypes.name, :as => :businesstypes
    indexes region.name, :as => :region
    ...
  end

Thanks again Pat for the help and an awesome search product.  Hope this
helps someone else out as well.

-e


On Sun, Jan 24, 2010 at 11:56 AM, Pat Allan <[email protected]>wrote:

> Hi Eric
>
> The reason geo searches won't work when searching on Business is because
> you have an array of floats (which Sphinx can't handle) for both latitude
> and longitude. Sphinx requires single float values for both of those
> attributes.
>
> So, you probably want to search on Addresses instead, and maybe group by
> business_id, to ensure businesses don't get duplicated in the search
> results.
> http://freelancing-god.github.com/ts/en/searching.html#grouping
>
> It's also worth noting that your business model has an address_id attribute
> - you probably want to refer to the has_many collection instead?
>  has addresses(:id), :as => :address_ids
>
> Don't forget that Sphinx doesn't understand SQL syntax for conditions - so
> your physical_only scope will not work at all.
>
> And I think the web_only scope failure is due to another small error -
> you've explicitly labelled the attribute as :web_only, but using
> :website_only in the scope. Also, it's best to keep attribute filters in
> :with, and field-focused queries in :conditions... so:
>
>  sphinx_scope(:web_only) {
>    {:with => {:web_only => true}}
>  }
>
> Hopefully this gets things working for you.
>
> Cheers
>
> --
> Pat
>
> On 24/01/2010, at 1:13 PM, Eric Lubow wrote:
>
> > I am struggling with trying to geo search an asssociated model.  My
> > relevant code is here: http://www.pastie.org/790850
> >
> > The context is that I have a business model and an address model.  I
> > want to be able to search for items in the business model that match
> > certain criteria (like the name or description) and fall within n
> > miles of a point the user enters.  If I search via the Address model,
> > this works, but then I can't get it to search all the attributes of
> > the model model.  If I search via the Business model, then I can't get
> > the geo search to work (which is most likely because I am doing it
> > wrong).  Is there a way to do this?
> >
> > I also want to be able to search web_only businesses (which is defined
> > via a sphinx_scope in the address model).  Basically a web_only
> > business is a business where it's address has a website_only=1 in the
> > SQL.  I also don't want businesses with website_only=1 returned in the
> > geo query even if they have a lat/lng associated with them (hence the
> > scope).  But when I put the scope in, Rails throws a no method error.
> > Is there anything in the code that jumps out at anyone? Thanks in
> > advance.
> >
> > --
> > 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]<thinking-sphinx%[email protected]>
> .
> > For more options, visit this group at
> http://groups.google.com/group/thinking-sphinx?hl=en.
> >
>
> --
> 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]<thinking-sphinx%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/thinking-sphinx?hl=en.
>
>

-- 
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