使用 elasticsearch 和 Tire 尝试搜索一些个人资料记录。
尝试获得性别 = 男性、age_from = 18、age_to = 30 的结果。目前,通过此设置,它会返回此年龄范围内的每个人,甚至包括女性。我怎样才能让它表现得好 只返回这个年龄段的男性?
if params['people']
tire.search(load: true, page: params[:page], per_page: 50, :default_operator => 'AND', :use_dis_max => true) do
query do
boolean do
should { range :age, {gte: params['people'][:age_from], lte: params['people'][:age_to]} }
should { string 'gender:male' } if params['people'][:gender] == "male"
should { string 'gender:female' } if params['people'][:gender] == "female"
end
end
to_curl
end
end
最佳答案
使用“must”代替“should”。 它应该可以工作。
关于ruby-on-rails-3 - Elasticsearch Tire on Rails,返回该年龄段的所有男性,但也返回女性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12696409/