@@ -16,7 +16,7 @@ class HasChild extends AbstractFilter
16
16
* Construct HasChild filter
17
17
*
18
18
* @param string|\Elastica\Query|\Elastica\Filter\AbstractFilter $query Query string or a Elastica\Query object or a filter
19
- * @param string $type Parent document type
19
+ * @param string|\Elastica\Type $type Child document type
20
20
*/
21
21
public function __construct ($ query , $ type = null )
22
22
{
@@ -50,29 +50,41 @@ public function setQuery($query)
50
50
*/
51
51
public function setFilter ($ filter )
52
52
{
53
- $ data = $ filter ->toArray ();
54
- return $ this ->setParam ('filter ' , $ data );
53
+ return $ this ->setParam ('filter ' , $ filter ->toArray ());
55
54
}
56
55
57
56
/**
58
- * Set type of the parent document
57
+ * Set type of the child document
59
58
*
60
- * @param string $type Parent document type
61
- * @return \Elastica\Filter\HasChild Current object
59
+ * @param string|\Elastica\Type $type Child document type
60
+ * @return \Elastica\Filter\HasParent Current object
62
61
*/
63
62
public function setType ($ type )
64
63
{
65
- return $ this ->setParam ('type ' , $ type );
64
+ if ($ type instanceof \Elastica \Type) {
65
+ $ type = $ type ->getName ();
66
+ }
67
+
68
+ return $ this ->setParam ('type ' , (string ) $ type );
66
69
}
67
70
68
71
/**
69
- * Sets the scope
70
- *
71
- * @param string $scope Scope
72
- * @return \Elastica\Filter\HasChild Current object
72
+ * Set minimum number of children are required to match for the parent doc to be considered a match
73
+ * @param int $count
74
+ * @return \Elastica\Filter\HasChild
75
+ */
76
+ public function setMinimumChildrenCount ($ count )
77
+ {
78
+ return $ this ->setParam ('min_children ' , (int ) $ count );
79
+ }
80
+
81
+ /**
82
+ * Set maximum number of children are required to match for the parent doc to be considered a match
83
+ * @param int $count
84
+ * @return \Elastica\Filter\HasChild
73
85
*/
74
- public function setScope ( $ scope )
86
+ public function setMaximumChildrenCount ( $ count )
75
87
{
76
- return $ this ->setParam ('_scope ' , $ scope );
88
+ return $ this ->setParam ('max_children ' , ( int ) $ count );
77
89
}
78
90
}
0 commit comments