Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adds has_child support for queries #431

Closed
wants to merge 1 commit into from

3 participants

@kofno

No description provided.

@travisbot

This pull request passes (merged f1f297c into 5129f8a).

@karmi
Owner

Hey, good idea, but I think we need a very good integration test as a demonstration of the feature (same as with nested queries...)

@karmi karmi closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 13, 2012
  1. @kofno
This page is out of date. Refresh to see the latest.
Showing with 32 additions and 0 deletions.
  1. +7 −0 lib/tire/search/query.rb
  2. +25 −0 test/unit/search_query_test.rb
View
7 lib/tire/search/query.rb
@@ -75,6 +75,13 @@ def dis_max(options={}, &block)
@value
end
+ def has_child(options={}, &block)
+ @has_child = Query.new(&block)
+ @value[:has_child] = options
+ @value[:has_child].update({ :query => @has_child.to_hash })
+ @value
+ end
+
def all
@value = { :match_all => {} }
@value
View
25 test/unit/search_query_test.rb
@@ -297,5 +297,30 @@ class QueryTest < Test::Unit::TestCase
end
+ context "Has child query" do
+
+ should "not raise an error when no block is given" do
+ assert_nothing_raised { Query.new.has_child }
+ end
+
+ should "allow search for documents with children" do
+ query = Query.new.has_child do
+ string 'foo'
+ end
+
+ assert_equal( { :has_child => { :query => { :query_string => { :query => 'foo' } } } },
+ query.to_hash )
+ end
+
+ should "encode options" do
+ query = Query.new.has_child('_scope' => 'foo', :type => 'bar') do
+ string 'baz'
+ end
+
+ assert_equal('foo', query.to_hash[:has_child]['_scope'])
+ assert_equal('bar', query.to_hash[:has_child][:type])
+ end
+ end
+
end
end
Something went wrong with that request. Please try again.