Answered on Stack Overflow. Let us know how you go. Cheers
-- Pat On 04/08/2012, at 3:03 PM, deneuxa wrote: > I've post my question here: > http://stackoverflow.com/questions/11809195/complex-search-with-thinking-sphinx > > Really need you help guys! > And thank you so much Pat for such a great gem ! > > Here my question too: > ------------------- > > I'd like to do a complex search with thinking sphinx: > > Search for users which: > > -> live in a city (city_id attribute) > > -> or has hability to move to a city (mobile_cities association) > > -> or live at a maximum distance from a lat/long point, the maximum distance > is different for each user and is set in a mobility_distance attribute. > > For now I did that with 3 differents search, I volontary set a big per_page > number, then i merge the 3 results on a single array, an then paginate this > array : > > #users living in the @city > search_set_living = search_set.merge({:city_id => @city.id }) > users_living = User.search :with => search_set_living.dup, > :page => 1, :per_page => 1000 > > #users declaring hability to move to the @city > search_set_mobile = search_set.merge({:mobile_cities_ids => @city.id }) > users_mobile = User.search :with => search_set_mobile.dup,:page => 1, > :per_page => 1000 > > #users living at a maximum distance from the origin point(custom distance for > each user, max 30km) > search_set_around = search_set.merge({"@geodist" => 0.0..30_000.0}) > users_around = User.search :geo => [@search_latitude * Math::PI / 180 , > @search_longitude * Math::PI / 180], > :with => search_set_around.dup, > :page => 1, :per_page => 1000 > users_around_filtered = users_around.dup.delete_if{|user| > (user.mobility_distance * 1000 )< user.sphinx_attributes['@geodist'] } > > > #merge the 3 results in a array > all_users = (users_mobile.flatten + users_around_filtered.flatten).uniq > > #look for facets and paginate the array > @facets = User.facets :with => {:user_id => all_users.map(&:id)} > @users_to_display = all_users.paginate(:page => params[:page], :per_page => > 10) > This is working fine but i'm not satisfied: -performance are not so good, -I > want the ability to sort on multiple attributes like this :order => > "created_at DESC, @relevance DESC" > > I want to do the exact same search but in a single sphinx's search. I know > that I should use the "OR Logic with Attribute Filters" from the docs but I > don't know how to mix it with a geo_search call... I really have no idea how > to do that, can you guys help me ? > > Many thanks, > > > > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/thinking-sphinx/-/Kk7PkpXm4nkJ. > 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.
