Skip to content

Loading…

Allow support of boost (and other options) to Terms Query #643

Closed
wants to merge 2 commits into from

3 participants

@moktin

Hi,

While using tire, I had problem using the boost on query terms.

I am pretty new to both tire and elasticsearch world, so maybe I am just doing it wrong.

With this indices

class User < ActiveRecord::Base
  include Tire::Model::Search
  mapping do
    indexes :comments do
      indexes :id, type: :integer
    end
  end
end

A request like :

search = User.search do
  query do
    boolean do
      should { 
        terms 'comments.id',  [1, 2], boost: 10
      }
    end
  end
end

produce such a result :

curl -X GET 'http://localhost:9200/users/user/_search?load=true&size=12&pretty' -d '
  {
    "query": {
      "bool": {
        "should": [
          {
            "terms": {
              "comments.id": [
                1,2
              ]
            }
          }
        ]
      }
    },
    "size": 12
  }
'

When I was waiting for something like that :

curl -X GET 'http://localhost:9200/users/user/_search?load=true&size=12&pretty' -d '
  {
    "query": {
      "bool": {
        "should": [
          {
            "terms": {
              "comments.id": [
                1,2
              ],
              "boost": 10
            }
          }
        ]
      }
    },
    "size": 12
  }
'

The attached pull request solve that.

Thank you to let me know if it helps or if you need some more informations

@brupm

:+1: Very useful PR. Although the build is failing.

@moktin

Hi,
The test are green locally :

Finished in 173.233226 seconds.

774 tests, 774 passed, 0 failures, 0 errors, 0 skips, 1745 assertions

I also noticed that most of the past builds on Travis are failing (see https://travis-ci.org/karmi/tire/builds) and it seems to be exactly the same errors.

@karmi are the builds having general problem on travis ? Or are they "real" failure ?

@karmi karmi added a commit that referenced this pull request
@moktin moktin Allow options for the `terms` query
Closes: #643
8db77cd
@karmi
Owner

Thanks!, merged & pushed.


Re the Travis failures -- there has been some incompatibilites with Ruby 1.8, which were shooting down the tests, and the percolator tests are still failing consistently. I have tried to fix it in 1a8b921, but will need to have a better look into it.

@karmi karmi closed this
@MrRuru MrRuru added a commit that referenced this pull request
@moktin moktin Allow options for the `terms` query
Closes: #643
d4a45eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 6 additions and 1 deletion.
  1. +1 −1 lib/tire/search/query.rb
  2. +5 −0 test/unit/search_query_test.rb
View
2 lib/tire/search/query.rb
@@ -20,7 +20,7 @@ def term(field, value, options={})
def terms(field, value, options={})
@value = { :terms => { field => value } }
- @value[:terms].update( { :minimum_match => options[:minimum_match] } ) if options[:minimum_match]
+ @value[:terms].update(options)
@value
end
View
5 test/unit/search_query_test.rb
@@ -55,6 +55,11 @@ class QueryTest < Test::Unit::TestCase
assert_equal( { :terms => { :foo => ['bar', 'baz'], :minimum_match => 2 } },
Query.new.terms(:foo, ['bar', 'baz'], :minimum_match => 2) )
end
+
+ should "allow set boost when searching for multiple terms" do
+ assert_equal( { :terms => { :foo => ['bar', 'baz'], :boost => 2 } },
+ Query.new.terms(:foo, ['bar', 'baz'], :boost => 2) )
+ end
end
context "Range query" do
Something went wrong with that request. Please try again.