co_author_ids は多値キーであるため、それを達成する方法がないと信じる十分な理由があります。ただし、単一値キーの場合、関数 query を使用して solr sort を使用することで、このカスケード効果を実現できます。http://wiki.apache.org/solr/FunctionQuery#Sort_By_Functionとともに、adjust_solr-params http://sunspot.github.io/docs/Sunspot/DSL/Adjustable.html
例: 次のようなクエリがあるとします。
@solr_search = User.solr_search do
paginate(:per_page => 20)
with(:has_email, true)
any_of do
with(:id,author_id) #assuming author id is a solr index
with(:hospitals_id).any_of(hopital_ids)
end
end
この場合、カスケード効果が必要で、author_id との完全一致をより優先したい場合は、この方法で行うことができます
@solr_search = User.solr_search do
paginate(:per_page => 20)
with(:has_email, true)
any_of do
with(:id,author_id) #assuming author id is a solr index
with(:hospitals_id).any_of(hopital_ids)
end
adjust_solr_params do |p|
p["sort"] = "if(author_id_i = #{id},1,0) desc" #note author_id_i solr eq of author_id
end
end
したがって、これは if(author_id_i = #{id},1,0) の値に基づいてソートされ、その代わりに、ユーザーと同じ auhtor_id を持つすべてのレコードが一番上に配置されます。
私はどういうわけかIF関数を使用して問題を抱えていたので、代わりに使用しました(実際には両方とも同じです):
@solr_search = User.solr_search do
paginate(:per_page => 20)
with(:has_email, true)
any_of do
with(:id,author_id) #assuming author id is a solr index
with(:hospitals_id).any_of(hopital_ids)
end
adjust_solr_params do |p|
p[:sort] = "min(abs(sub(author_id_i,#{id})),1) asc"
end
end
これに対する解決策を探しているときに、これもhttp://wiki.apache.org/solr/SpatialSearchに出くわしました。距離で並べ替えたい場合は、次のようにすることができます。
@solr_search = User.solr_search do
paginate(:per_page => 20)
with(:has_email, true)
any_of do
with(:id,author_id) #assuming author id is a solr index
with(:hospitals_id).any_of(hopital_ids)
end
adjust_solr_params do |p|
p[:pt] = "#{latitude_of_your_interest},#{longitude_of_your_interest}"
p[:sfield] = :author_location #your solr index which stores location of the author
p[:sort] = "geodist() asc"
end
end
全体として、p["sort"] を使用して多くのクールなことを実行できると思いますが、この特定のケースでは、多値フィールドであるため実行できません (私見) 例:
マップ関数で多値フィールドを使用する
Solr 関数クエリを操作する複数値フィールドのカウント
多値フィールドにインクルード関数を提供できればいいのにと思います。
p["sort"] ="if(include(co_authors_ids,#{id}), 1, 0) desc"
しかし、今のところそれは不可能です(再び私見)。