我想用思考狮身人面像做一个复杂的搜索:
搜索以下用户:-> 居住在城市(city_id 属性)-> 或有能力移动到城市(mobile_cities 关联)-> 或居住在距纬度/经度点的最大距离处,最大距离不同每个用户并设置在移动距离属性中。
现在我用 3 个不同的搜索来做到这一点,我自愿设置了一个大的 per_page 编号,然后我将 3 个结果合并到一个数组中,然后对这个数组进行分页:
#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)
这工作正常,但我不满意:-性能不太好,-我希望能够像这样对多个属性进行排序:order => "created_at DESC,@relevance DESC"
我想做完全相同的搜索,但只在一个狮身人面像的搜索中。我知道我应该使用文档中的“OR Logic with Attribute Filters”,但我不知道如何将它与 geo_search 调用混合使用……我真的不知道该怎么做,你们能帮帮我吗?
非常感谢,