File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1
1
CHANGES
2
2
3
+ 2014-07-02
4
+ - Add setPostFilter method to Elastica\Query (http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_filtering_queries_and_aggregations.html#_post_filter)
5
+
3
6
2014-06-30
4
7
- Add Reverse Nested aggregation (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html).
5
8
Original file line number Diff line number Diff line change @@ -348,6 +348,10 @@ public function toArray()
348
348
unset($ this ->_params ['facets ' ]);
349
349
}
350
350
351
+ if (isset ($ this ->_params ['post_filter ' ]) && 0 === count ($ this ->_params ['post_filter ' ])) {
352
+ unset($ this ->_params ['post_filter ' ]);
353
+ }
354
+
351
355
return $ this ->_params ;
352
356
}
353
357
@@ -399,6 +403,17 @@ public function setSource(array $fields)
399
403
{
400
404
return $ this ->setParam ('_source ' , $ fields );
401
405
}
406
+
407
+ /**
408
+ * Sets post_filter argument for the query. The filter is applied after the query has executed
409
+ * @param array $post
410
+ * @return \Elastica\Query Current object
411
+ * @link http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_filtering_queries_and_aggregations.html#_post_filter
412
+ */
413
+ public function setPostFilter (array $ post )
414
+ {
415
+ return $ this ->setParam ("post_filter " , $ post );
416
+ }
402
417
}
403
418
404
419
Original file line number Diff line number Diff line change 9
9
use Elastica \Query \Text ;
10
10
use Elastica \Query ;
11
11
use Elastica \Facet \Terms ;
12
+ use Elastica \Filter \Term as FilterTerm ;
12
13
use Elastica \Test \Base as BaseTest ;
13
14
14
15
class QueryTest extends BaseTest
@@ -191,4 +192,21 @@ public function testSetFacets()
191
192
192
193
$ this ->assertArrayNotHasKey ('facets ' , $ query ->toArray ());
193
194
}
195
+
196
+ public function testSetPostQuery ()
197
+ {
198
+ $ query = new Query ();
199
+
200
+ $ post_filter = new FilterTerm (['color ' => 'green ' ]);
201
+ $ query ->setPostFilter ($ post_filter ->toArray ());
202
+
203
+ $ data = $ query ->toArray ();
204
+
205
+ $ this ->assertArrayHasKey ('post_filter ' , $ data );
206
+ $ this ->assertEquals (array ('term ' => array ('color ' => 'green ' )), $ data ['post_filter ' ]);
207
+
208
+ $ query ->setPostFilter (array ());
209
+
210
+ $ this ->assertArrayNotHasKey ('post_filter ' , $ query ->toArray ());
211
+ }
194
212
}
You can’t perform that action at this time.
0 commit comments