1414use ONGR \ElasticsearchBundle \DSL \Aggregation \TermsAggregation ;
1515use ONGR \ElasticsearchBundle \DSL \Query \RangeQuery ;
1616use ONGR \ElasticsearchBundle \ORM \Repository ;
17- use ONGR \ElasticsearchBundle \Test \ElasticsearchTestCase ;
17+ use ONGR \ElasticsearchBundle \Test \AbstractElasticsearchTestCase ;
1818
19- class TermsAggregationTest extends ElasticsearchTestCase
19+ class TermsAggregationTest extends AbstractElasticsearchTestCase
2020{
2121 /**
2222 * {@inheritdoc}
@@ -107,7 +107,7 @@ public function getTermsAggregationData()
107107 $ aggregation = [
108108 'name ' => 'test_agg ' ,
109109 'field ' => 'surface ' ,
110- 'order ' => [TermsAggregation:: MODE_TERM , TermsAggregation:: DIRECTION_ASC ],
110+ 'order ' => [' _term ' , ' asc ' ],
111111 ];
112112
113113 $ result = [
@@ -134,7 +134,7 @@ public function getTermsAggregationData()
134134 $ aggregation = [
135135 'name ' => 'test_agg ' ,
136136 'field ' => 'surface ' ,
137- 'min_document_cound ' => 2 ,
137+ 'min_document_count ' => 2 ,
138138 ];
139139
140140 $ result = [
@@ -284,6 +284,30 @@ public function testTermsAggregationWithRangeQuery($aggregation, $parameters, $e
284284 $ this ->assertArraySubset ($ expectedResult , $ results ['aggregations ' ]);
285285 }
286286
287+ /**
288+ * Test for terms aggregation with shard_size, collect_mode, shard_min_doc_count.
289+ */
290+ public function testTermsAggregationWithCollectMode ()
291+ {
292+ /** @var Repository $repo */
293+ $ repo = $ this ->getManager ()->getRepository ('AcmeTestBundle:Product ' );
294+ $ aggregationFoo = new TermsAggregation ('test_foo ' );
295+ $ aggregationFoo ->setField ('title ' );
296+ $ aggregationFoo ->addParameter ('size ' , 5 );
297+ $ aggregationFoo ->addParameter ('shard_size ' , 5 );
298+ $ aggregationFoo ->addParameter ('execution_hint ' , 'map ' );
299+ $ aggregationFoo ->addParameter ('collect_mode ' , 'breadth_first ' );
300+
301+ $ aggregationBar = new TermsAggregation ('test_bar ' );
302+ $ aggregationBar ->setField ('title ' );
303+ $ aggregationBar ->addParameter ('shard_min_doc_count ' , 5 );
304+ $ aggregationFoo ->addAggregation ($ aggregationBar );
305+
306+ $ search = $ repo ->createSearch ()->addAggregation ($ aggregationFoo );
307+ $ results = $ repo ->execute ($ search , Repository::RESULTS_RAW );
308+ $ this ->assertEquals (3 , count ($ results ['aggregations ' ][$ aggregationFoo ->getName ()]['buckets ' ]));
309+ }
310+
287311 /**
288312 * Builds term aggregation.
289313 *
@@ -297,23 +321,23 @@ private function getAggregation($options)
297321 $ term ->setField ($ options ['field ' ]);
298322
299323 if (array_key_exists ('exclude ' , $ options )) {
300- $ term ->setExclude ( $ options ['exclude ' ]);
324+ $ term ->addParameter ( ' exclude ' , $ options ['exclude ' ]);
301325 }
302326
303327 if (array_key_exists ('include ' , $ options )) {
304- $ term ->setInclude ( $ options ['include ' ]);
328+ $ term ->addParameter ( ' include ' , $ options ['include ' ]);
305329 }
306330
307331 if (array_key_exists ('min_document_count ' , $ options )) {
308- $ term ->setMinDocumentCount ( $ options ['min_document_count ' ]);
332+ $ term ->addParameter ( ' min_doc_count ' , $ options ['min_document_count ' ]);
309333 }
310334
311335 if (array_key_exists ('order ' , $ options )) {
312- call_user_func_array ([ $ term, ' setOrder ' ], $ options ['order ' ]);
336+ $ term-> addParameter ( ' order ' , [ $ options [ ' order ' ][ 0 ] => $ options ['order ' ][ 1 ] ]);
313337 }
314338
315339 if (array_key_exists ('size ' , $ options )) {
316- $ term ->setSize ( $ options ['size ' ]);
340+ $ term ->addParameter ( ' size ' , $ options ['size ' ]);
317341 }
318342
319343 return $ term ;
0 commit comments