2

I'm using tire with elasticsearch, and I'm stumped how to create a boolean query with the minimum_number_should_match option while also tossing it a set of queries stored in a block.

So, I have

options = {:minimum_number_should_match => 1}
s = Tire.search 'variations' do |search|
      search.query do |query|
        query.boolean options, &keyword_query(params[:keyword]) unless params[:keyword].blank?
      end
    end

def keyword_query(keyword)
    lambda do |boolean|
      boolean.should { string "name:*#{keyword}*"}
      boolean.should { string "number:*#{keyword}*"}
      boolean.should { string "nrf:*#{keyword}*"}
      boolean.should { string "base_color:*#{keyword}*"}
      boolean.should { string "skus:*#{keyword}*"}
      boolean.should { string "color_name:*#{keyword}*"}
    end
  end`

But the option is not being added to the end query request to ElasticSearch. keyword_query returns a lambda. Is there another way I can add the options to this boolean query?

timting
  • 57
  • 7
  • Figured it out - right now tire only adds options to the boolean request the first time you call boolean. I had a bunch of other boolean queries before the one I listed above, and so my options were getting dropped into the ether. – timting Mar 23 '12 at 23:33
  • You should post your solution as your answer then accept it. [Check this out for more info](http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/) – Azolo Mar 24 '12 at 02:18
  • Post your damn answer, damn it!!!!!! – Henley Jan 12 '14 at 01:41

1 Answers1

0

Figured it out - as of now, tire only adds options to the boolean request the first time you call boolean. I had a bunch of other boolean queries before the one I listed above, and so my options were getting dropped into the ether.

timting
  • 57
  • 7