Skip to content
This repository

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

Closed
wants to merge 2 commits into from

3 participants

Bruno Miranda Karel Minarik

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

Bruno Miranda

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

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 ?

Karel Minarik karmi referenced this pull request from a commit February 26, 2013
Allow options for the `terms` query
Closes: #643
8db77cd
Karel Minarik
Owner
karmi commented March 27, 2013

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.

Karel Minarik karmi closed this March 27, 2013
David Ruyer MrRuru referenced this pull request from a commit in jobteaser/tire February 26, 2013
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
This page is out of date. Refresh to see the latest.
2  lib/tire/search/query.rb
@@ -20,7 +20,7 @@ def term(field, value, options={})
20 20
 
21 21
       def terms(field, value, options={})
22 22
         @value = { :terms => { field => value } }
23  
-        @value[:terms].update( { :minimum_match => options[:minimum_match] } ) if options[:minimum_match]
  23
+        @value[:terms].update(options)
24 24
         @value
25 25
       end
26 26
 
5  test/unit/search_query_test.rb
@@ -55,6 +55,11 @@ class QueryTest < Test::Unit::TestCase
55 55
         assert_equal( { :terms => { :foo => ['bar', 'baz'], :minimum_match => 2 } },
56 56
                       Query.new.terms(:foo, ['bar', 'baz'], :minimum_match => 2) )
57 57
       end
  58
+
  59
+      should "allow set boost when searching for multiple terms" do
  60
+        assert_equal( { :terms => { :foo => ['bar', 'baz'], :boost => 2 } },
  61
+                      Query.new.terms(:foo, ['bar', 'baz'], :boost => 2) )
  62
+      end
58 63
     end
59 64
 
60 65
     context "Range query" do
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.