2

いくつかのプロファイルレコードを検索しようとしているelasticsearchとTireimを使用します。

性別=男性、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
4

2 に答える 2

2

shouldの代わりにmustを使用してください。動作するはずです。

于 2012-10-02T19:21:05.960 に答える
0

私はルビーをプログラムしていませんが...

:default_operator => 'OR'

「OR」を「AND」に変更してみてください

編集OKラウンド2、これは楽しいです...

これは間違っているように私には思えます

should { string 'gender:male' } if params['people'][:gender] == "male"
should { string 'gender:female' } if params['people'][:gender] == "female"

その上の:age 1を見るだけで、これはうまく機能しないでしょう...

should { string :gender, {eq: params['people'][:gender]} }

しかし、繰り返しますが、私はルビーでプログラムしません...

于 2012-10-02T18:56:23.603 に答える