Hi Sjors
Sphinx has no concept of associated records - the indexed document for a city
will have a single street field which is all street names concatenated together
(with a space in between each one).
If you want to know which street matches, then you really should be searching
on Street instead. If you only want one street returned for any city, you can
group results.
define_index do
indexes city.name, :as => :city
indexes name, :as => :street_name
has city_id
set_property :min_infix_len => 1
end
And then searching:
Street.search params[:search], :group_by => 'city_id', :group_function =>
:attr
Will this do the job?
--
Pat
On 01/07/2011, at 8:29 AM, Sjors wrote:
> I have two models, e.g. like this:
> City
> Street
> Where a city has many streets.
>
> I built a search method on the city model, like this:
>
> define_index do
> indexes :name
> indexes streets.name, :as => :street_name
>
> set_property :min_infix_len => 1
> end
>
> In the controller:
> City.search :params[:search]
>
> The user can search either by city or by street name. The search works
> fine, but because it just returns a City object, I'm unable to figure
> out which Street object was matched. How do I find it?
>
> I can't use excerpts to figure it out, because - see my previous post
> - they don't work for partial matches and they also don't seem to work
> if the match is not in the primary model.
>
> Thanks,
>
> Sjors
>
> --
> 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.
>
--
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.