複雜的搜索我想要做的與思維獅身人面像一個複雜的搜索:與思考獅身人面像
搜索哪些用戶: - >住在城市(city_id屬性) - >或具有hability移動到一個城市(mobile_cities association) - >或者居住在距經緯度點最大距離處,每個用戶的最大距離是不同的,並且設置在mobility_distance屬性中。
現在我這樣做,與3型動物進行搜索,我volontary設置一個大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)
這是工作的罰款但我不滿意: - 性能都不太好, -I要作爲排序依據這樣的多重屬性的能力:爲了=>「created_at DESC,@relevance DESC」
我想做的確切相同的搜索,但在一個獅身人面像的搜索。 我知道我應該使用"OR Logic with Attribute Filters" from the docs,但我不知道如何將它與一個geo_search調用... 我真的不知道該怎麼做, 你們能幫我嗎?
非常感謝,
太棒了!我只需要修改一下你的語法就可以使它工作: – alex 2012-08-05 15:12:01