Chad has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/159802

Change subject: Updating Elastica to 1.3.0.0 release to match 1.3.x requirement 
of ES
......................................................................

Updating Elastica to 1.3.0.0 release to match 1.3.x requirement of ES

Change-Id: Id9f85924ee9d792a8679554888e8cbf5913aa39c
---
M Elastica.php
M Elastica/changes.txt
M Elastica/composer.json
A Elastica/lib/Elastica/Aggregation/ReverseNested.php
M Elastica/lib/Elastica/Param.php
M Elastica/lib/Elastica/Query.php
M Elastica/lib/Elastica/Query/ConstantScore.php
M Elastica/lib/Elastica/Query/Filtered.php
M Elastica/lib/Elastica/Query/FunctionScore.php
M Elastica/lib/Elastica/Transport/Guzzle.php
M Elastica/lib/Elastica/Transport/Http.php
M Elastica/lib/Elastica/Transport/Memcache.php
M Elastica/lib/Elastica/Transport/Thrift.php
M Elastica/test/bin/run_elasticsearch.sh
A Elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
M Elastica/test/lib/Elastica/Test/Base.php
M Elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php
M Elastica/test/lib/Elastica/Test/Query/FilteredTest.php
M Elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php
A Elastica/test/lib/Elastica/Test/Query/PostFilterTest.php
M Elastica/test/lib/Elastica/Test/Transport/HttpTest.php
21 files changed, 477 insertions(+), 43 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Elastica 
refs/changes/02/159802/1

diff --git a/Elastica.php b/Elastica.php
index 958e879..e88f5b8 100644
--- a/Elastica.php
+++ b/Elastica.php
@@ -63,6 +63,7 @@
 $wgAutoloadClasses['Elastica\Type'] = $elasticaDir . 'Type.php';
 $wgAutoloadClasses['Elastica\Util'] = $elasticaDir . 'Util.php';
 $wgAutoloadClasses['Elastica\Aggregation\Cardinality'] = $elasticaDir . 
'Aggregation/Cardinality.php';
+$wgAutoloadClasses['Elastica\Aggregation\ReverseNested'] = $elasticaDir . 
'Aggregation/ReverseNested.php';
 $wgAutoloadClasses['Elastica\Bulk\Action'] = $elasticaDir . 'Bulk/Action.php';
 $wgAutoloadClasses['Elastica\Bulk\Response'] = $elasticaDir . 
'Bulk/Response.php';
 $wgAutoloadClasses['Elastica\Bulk\ResponseSet'] = $elasticaDir . 
'Bulk/ResponseSet.php';
diff --git a/Elastica/changes.txt b/Elastica/changes.txt
index b9d99a9..525a633 100755
--- a/Elastica/changes.txt
+++ b/Elastica/changes.txt
@@ -1,5 +1,31 @@
 CHANGES
 
+2014-07-26
+- Release v1.3.0.0
+- Prepare Elastica Release v1.3.0.0
+
+2014-07-25
+- Update to elasticsearch version 1.3.0 
http://www.elasticsearch.org/downloads/1-3-0/
+
+2014-07-14
+ - Add setQuery() method to Elastica\Query\ConstantScore #653
+
+2014-07-12
+ - Be able to configure ES host/port via ENV var in test env #652
+
+2014-07-07
+ - Fix FunstionScore Query random_score without seed bug. #647
+
+2014-07-02
+- Add setPostFilter method to Elastica\Query 
(http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_filtering_queries_and_aggregations.html#_post_filter)
 #645
+
+2014-06-30
+- Add Reverse Nested aggregation 
(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html).
 #642
+
+2014-06-14
+- Release v1.2.1.0
+- Removed the requirement to set arguments filter and/or query in Filtered, 
according to the documentation: 
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html
 #616
+
 2014-06-13
 - Stop ClientTest->testDeleteIdsIdxStringTypeString from failing 1/3 of the 
time #634
 - Stop ScanAndScrollTest->testQuerySizeOverride from failing frequently for no 
reason #635
diff --git a/Elastica/composer.json b/Elastica/composer.json
index 62e5d45..70c2832 100644
--- a/Elastica/composer.json
+++ b/Elastica/composer.json
@@ -31,5 +31,10 @@
             "Elastica": "lib/",
             "Elastica\\Test": "test/lib/"
         }
+    },
+    "extra": {
+        "branch-alias": {
+            "dev-master": "1.2.x-dev"
+        }
     }
 }
diff --git a/Elastica/lib/Elastica/Aggregation/ReverseNested.php 
b/Elastica/lib/Elastica/Aggregation/ReverseNested.php
new file mode 100644
index 0000000..d4056f1
--- /dev/null
+++ b/Elastica/lib/Elastica/Aggregation/ReverseNested.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Elastica\Aggregation;
+
+/**
+ * Reversed Nested Aggregation
+ *
+ * @package Elastica\Aggregation
+ * @link 
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
+ */
+class ReverseNested extends AbstractAggregation
+{
+    /**
+     * @param string $name The name of this aggregation
+     * @param string $path Optional path to the nested object for this 
aggregation. Defaults to the root of the main document.
+     */
+    public function __construct($name, $path = null)
+    {
+        parent::__construct($name);
+
+        if ($path !== null) {
+            $this->setPath($path);
+        }
+    }
+
+    /**
+     * Set the nested path for this aggregation
+     *
+     * @param string $path
+     * @return ReverseNested
+     */
+    public function setPath($path)
+    {
+        return $this->setParam("path", $path);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function toArray()
+    {
+        $array = parent::toArray();
+
+        // ensure we have an object for the reverse_nested key.
+        // if we don't have a path, then this would otherwise get encoded as 
an empty array, which is invalid.
+        $array['reverse_nested'] = (object)$array['reverse_nested'];
+
+        return $array;
+    }
+}
diff --git a/Elastica/lib/Elastica/Param.php b/Elastica/lib/Elastica/Param.php
index d84f18e..38a45d1 100644
--- a/Elastica/lib/Elastica/Param.php
+++ b/Elastica/lib/Elastica/Param.php
@@ -132,7 +132,7 @@
      */
     public function getParam($key)
     {
-        if (!isset($this->_params[$key])) {
+        if (!$this->hasParam($key)) {
             throw new InvalidException('Param ' . $key . ' does not exist');
         }
 
diff --git a/Elastica/lib/Elastica/Query.php b/Elastica/lib/Elastica/Query.php
index b729654..2f37f2e 100755
--- a/Elastica/lib/Elastica/Query.php
+++ b/Elastica/lib/Elastica/Query.php
@@ -348,6 +348,10 @@
             unset($this->_params['facets']);
         }
 
+        if (isset($this->_params['post_filter']) && 0 === 
count($this->_params['post_filter'])) {
+            unset($this->_params['post_filter']);
+        }
+
         return $this->_params;
     }
 
@@ -399,6 +403,17 @@
     {
         return $this->setParam('_source', $fields);
     }
+
+    /**
+     * Sets post_filter argument for the query. The filter is applied after 
the query has executed
+     * @param   array $post
+     * @return  \Elastica\Query Current object
+     * @link    
http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_filtering_queries_and_aggregations.html#_post_filter
+     */
+    public function setPostFilter(array $post)
+    {
+        return $this->setParam("post_filter", $post);
+    }
 }
 
 
diff --git a/Elastica/lib/Elastica/Query/ConstantScore.php 
b/Elastica/lib/Elastica/Query/ConstantScore.php
index 69cff5a..1685460 100644
--- a/Elastica/lib/Elastica/Query/ConstantScore.php
+++ b/Elastica/lib/Elastica/Query/ConstantScore.php
@@ -41,6 +41,21 @@
     }
 
     /**
+     * Set query
+     *
+     * @param array|\Elastica\Query\AbstractQuery $query
+     * @return \Elastica\Query\ConstantScore         Query object
+     */
+    public function setQuery($query)
+    {
+        if ($query instanceof AbstractQuery) {
+            $query = $query->toArray();
+        }
+
+        return $this->setParam('query', $query);
+    }
+
+    /**
      * Set boost
      *
      * @param  float                        $boost
diff --git a/Elastica/lib/Elastica/Query/Filtered.php 
b/Elastica/lib/Elastica/Query/Filtered.php
index 74a4c80..c28d4cd 100644
--- a/Elastica/lib/Elastica/Query/Filtered.php
+++ b/Elastica/lib/Elastica/Query/Filtered.php
@@ -1,7 +1,9 @@
 <?php
 
 namespace Elastica\Query;
+
 use Elastica\Filter\AbstractFilter;
+use Elastica\Exception\InvalidException;
 
 /**
  * Filtered query. Needs a query and a filter
@@ -14,27 +16,12 @@
 class Filtered extends AbstractQuery
 {
     /**
-     * Query
-     *
-     * @var \Elastica\Query\AbstractQuery Query object
-     */
-    protected $_query = null;
-
-    /**
-     * Filter
-     *
-     * @var \Elastica\Filter\AbstractFilter Filter object
-     */
-    protected $_filter = null;
-
-    /**
      * Constructs a filtered query
      *
-     * @param \Elastica\Query\AbstractQuery   $query  Query object
-     * @param \Elastica\Filter\AbstractFilter $filter Filter object
+     * @param \Elastica\Query\AbstractQuery   $query  OPTIONAL Query object
+     * @param \Elastica\Filter\AbstractFilter $filter OPTIONAL Filter object
      */
-    public function __construct(AbstractQuery $query, AbstractFilter $filter)
-    {
+    public function __construct(AbstractQuery $query = null, AbstractFilter 
$filter = null) {
         $this->setQuery($query);
         $this->setFilter($filter);
     }
@@ -45,11 +32,9 @@
      * @param  \Elastica\Query\AbstractQuery $query Query object
      * @return \Elastica\Query\Filtered      Current object
      */
-    public function setQuery(AbstractQuery $query)
+    public function setQuery(AbstractQuery $query = null)
     {
-        $this->_query = $query;
-
-        return $this;
+        return $this->setParam('query', $query);
     }
 
     /**
@@ -58,11 +43,9 @@
      * @param  \Elastica\Filter\AbstractFilter $filter Filter object
      * @return \Elastica\Query\Filtered        Current object
      */
-    public function setFilter(AbstractFilter $filter)
+    public function setFilter(AbstractFilter $filter = null)
     {
-        $this->_filter = $filter;
-
-        return $this;
+        return $this->setParam('filter', $filter);
     }
 
     /**
@@ -72,7 +55,7 @@
      */
     public function getFilter()
     {
-        return $this->_filter;
+        return $this->getParam('filter');
     }
 
     /**
@@ -82,7 +65,7 @@
      */
     public function getQuery()
     {
-        return $this->_query;
+        return $this->getParam('query');
     }
 
     /**
@@ -93,9 +76,20 @@
      */
     public function toArray()
     {
-        return array('filtered' => array(
-            'query' => $this->_query->toArray(),
-            'filter' => $this->_filter->toArray()
-        ));
+        $filtered = array();
+
+        if ($this->hasParam('query') && $this->getParam('query') instanceof 
AbstractQuery) {
+            $filtered['query'] = $this->getParam('query')->toArray();
+        }
+
+        if ($this->hasParam('filter') && $this->getParam('filter') instanceof 
AbstractFilter) {
+            $filtered['filter'] = $this->getParam('filter')->toArray();
+        }
+
+        if (empty($filtered)) {
+            throw new InvalidException('A query and/or filter is required');
+        }
+            
+        return array('filtered' => $filtered);
     }
 }
diff --git a/Elastica/lib/Elastica/Query/FunctionScore.php 
b/Elastica/lib/Elastica/Query/FunctionScore.php
index 26f14f1..8230c86 100755
--- a/Elastica/lib/Elastica/Query/FunctionScore.php
+++ b/Elastica/lib/Elastica/Query/FunctionScore.php
@@ -171,9 +171,9 @@
      */
     public function setRandomScore($seed = NULL)
     {
-        $seedParam = array();
+        $seedParam = new \stdClass();
         if (!is_null($seed)) {
-            $seedParam['seed'] = $seed;
+            $seedParam->seed = $seed;
         }
         return $this->setParam('random_score', $seedParam);
     }
diff --git a/Elastica/lib/Elastica/Transport/Guzzle.php 
b/Elastica/lib/Elastica/Transport/Guzzle.php
index 38e08ba..96ad897 100644
--- a/Elastica/lib/Elastica/Transport/Guzzle.php
+++ b/Elastica/lib/Elastica/Transport/Guzzle.php
@@ -70,7 +70,7 @@
             $req->setHeaders($connection->hasConfig('headers') ?: array());
 
             $data = $request->getData();
-            if (isset($data) && !empty($data)) {
+            if (!empty($data) || '0' === $data) {
 
                 if ($req->getMethod() == Request::GET) {
                     $req->setMethod(Request::POST);
diff --git a/Elastica/lib/Elastica/Transport/Http.php 
b/Elastica/lib/Elastica/Transport/Http.php
index 6dbba1a..5606dbb 100644
--- a/Elastica/lib/Elastica/Transport/Http.php
+++ b/Elastica/lib/Elastica/Transport/Http.php
@@ -93,7 +93,7 @@
         $data = $request->getData();
         $httpMethod = $request->getMethod();
 
-        if (isset($data) && !empty($data)) {
+        if (!empty($data) || '0' === $data) {
             if ($this->hasParam('postWithRequestBody') && 
$this->getParam('postWithRequestBody') == true) {
                 $httpMethod = Request::POST;
             }
diff --git a/Elastica/lib/Elastica/Transport/Memcache.php 
b/Elastica/lib/Elastica/Transport/Memcache.php
index b8a3bb0..cf047b5 100644
--- a/Elastica/lib/Elastica/Transport/Memcache.php
+++ b/Elastica/lib/Elastica/Transport/Memcache.php
@@ -39,7 +39,7 @@
 
         $content = '';
 
-        if (!empty($data)) {
+        if (!empty($data) || '0' === $data) {
             if (is_array($data)) {
                 $content = JSON::stringify($data);
             } else {
diff --git a/Elastica/lib/Elastica/Transport/Thrift.php 
b/Elastica/lib/Elastica/Transport/Thrift.php
index 0b6225c..f58c51a 100644
--- a/Elastica/lib/Elastica/Transport/Thrift.php
+++ b/Elastica/lib/Elastica/Transport/Thrift.php
@@ -135,7 +135,7 @@
             }
 
             $data = $request->getData();
-            if (!empty($data)) {
+            if (!empty($data) || '0' === $data) {
                 if (is_array($data)) {
                     $content = JSON::stringify($data);
                 } else {
diff --git a/Elastica/test/bin/run_elasticsearch.sh 
b/Elastica/test/bin/run_elasticsearch.sh
index 101fa26..ddbbef3 100755
--- a/Elastica/test/bin/run_elasticsearch.sh
+++ b/Elastica/test/bin/run_elasticsearch.sh
@@ -14,6 +14,7 @@
 
 export JAVA_OPTS="-server"
 
+# start 3 elasticsearch instances
 for i in 0 1 2
 do
     echo "Setup node #$i"
diff --git a/Elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php 
b/Elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
new file mode 100644
index 0000000..215dac6
--- /dev/null
+++ b/Elastica/test/lib/Elastica/Test/Aggregation/ReverseNestedTest.php
@@ -0,0 +1,124 @@
+<?php
+
+namespace Elastica\Test\Aggregation;
+
+use Elastica\Aggregation\Terms;
+use Elastica\Aggregation\Nested;
+use Elastica\Aggregation\ReverseNested;
+use Elastica\Document;
+use Elastica\Query;
+use Elastica\Type\Mapping;
+
+class ReverseNestedTest extends BaseAggregationTest
+{
+    protected function setUp()
+    {
+        parent::setUp();
+        $this->_index = $this->_createIndex("nested");
+        $mapping = new Mapping();
+        $mapping->setProperties(array(
+            "comments" => array(
+                "type" => "nested",
+                "properties" => array(
+                    "name" => array("type" => "string"),
+                    "body" => array("type" => "string")
+                )
+            )
+        ));
+        $type = $this->_index->getType("test");
+        $type->setMapping($mapping);
+        $docs = array(
+            new Document("1", array(
+                "comments" => array(
+                    array(
+                        "name" => "bob",
+                        "body" => "this is bobs comment",
+                    ),
+                    array(
+                        "name" => "john",
+                        "body" => "this is johns comment",
+                    ),
+                ),
+                "tags" => array("foo", "bar"),
+            )),
+            new Document("2", array(
+                 "comments" => array(
+                    array(
+                        "name" => "bob",
+                        "body" => "this is another comment from bob",
+                    ),
+                    array(
+                        "name" => "susan",
+                        "body" => "this is susans comment",
+                    ),
+                ),
+                "tags" => array("foo", "baz"),
+            ))
+        );
+        $type->addDocuments($docs);
+        $this->_index->refresh();
+    }
+
+    public function testPathNotSetIfNull()
+    {
+        $agg = new ReverseNested('nested');
+        $this->assertFalse($agg->hasParam('path'));
+    }
+
+    public function testPathSetIfNotNull()
+    {
+        $agg = new ReverseNested('nested', 'some_field');
+        $this->assertEquals('some_field', $agg->getParam('path'));
+    }
+
+    public function testReverseNestedAggregation()
+    {
+        $agg = new Nested("comments", "comments");
+        $names = new Terms("name");
+        $names->setField("comments.name");
+
+        $tags = new Terms("tags");
+        $tags->setField("tags");
+
+        $reverseNested = new ReverseNested("main");
+        $reverseNested->addAggregation($tags);
+
+        $names->addAggregation($reverseNested);
+
+        $agg->addAggregation($names);
+
+        $query = new Query();
+        $query->addAggregation($agg);
+        $results = $this->_index->search($query)->getAggregation("comments");
+
+        $this->assertArrayHasKey('name', $results);
+        $nameResults = $results['name'];
+
+        $this->assertCount(3, $nameResults['buckets']);
+
+        // bob
+        $this->assertEquals('bob', $nameResults['buckets'][0]['key']);
+        $tags = array(
+            array('key' => 'foo', 'doc_count' => 2),
+            array('key' => 'bar', 'doc_count' => 1),
+            array('key' => 'baz', 'doc_count' => 1),
+        );
+        $this->assertEquals($tags, 
$nameResults['buckets'][0]['main']['tags']['buckets']);
+
+        // john
+        $this->assertEquals('john', $nameResults['buckets'][1]['key']);
+        $tags = array(
+            array('key' => 'bar', 'doc_count' => 1),
+            array('key' => 'foo', 'doc_count' => 1),
+        );
+        $this->assertEquals($tags, 
$nameResults['buckets'][1]['main']['tags']['buckets']);
+
+        // susan
+        $this->assertEquals('susan', $nameResults['buckets'][2]['key']);
+        $tags = array(
+            array('key' => 'baz', 'doc_count' => 1),
+            array('key' => 'foo', 'doc_count' => 1),
+        );
+        $this->assertEquals($tags, 
$nameResults['buckets'][2]['main']['tags']['buckets']);
+    }
+}
diff --git a/Elastica/test/lib/Elastica/Test/Base.php 
b/Elastica/test/lib/Elastica/Test/Base.php
index 530718a..55cd887 100644
--- a/Elastica/test/lib/Elastica/Test/Base.php
+++ b/Elastica/test/lib/Elastica/Test/Base.php
@@ -8,7 +8,10 @@
 {
     protected function _getClient()
     {
-        return new Client();
+        return new Client(array(
+            'host' => getenv('ES_HOST') ?: 'localhost',
+            'port' => getenv('ES_PORT') ?: 9200,
+        ));
     }
 
     /**
diff --git a/Elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php 
b/Elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php
index 9189c30..27143eb 100644
--- a/Elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php
+++ b/Elastica/test/lib/Elastica/Test/Query/ConstantScoreTest.php
@@ -5,7 +5,11 @@
 use Elastica\Filter\Term;
 use Elastica\Filter\Ids;
 use Elastica\Query\ConstantScore;
+use Elastica\Query\MatchAll;
 use Elastica\Test\Base as BaseTest;
+use Elastica\Index;
+use Elastica\Document;
+use Elastica\Type;
 
 class ConstantScoreTest extends BaseTest
 {
@@ -101,6 +105,49 @@
 
     }
 
+    public function testQuery()
+    {
+
+        $client = $this->_getClient();
+        $index = new Index($client, 'test');
+        $index->create(array(), true);
+
+        $type = new Type($index, 'constant_score');
+
+        $doc = new Document(1, array('id' => 1, 'email' => '[email protected]', 
'username' => 'hans'));
+        $type->addDocument($doc);
+        $doc = new Document(2, array('id' => 2, 'email' => '[email protected]', 
'username' => 'emil'));
+        $type->addDocument($doc);
+        $doc = new Document(3, array('id' => 3, 'email' => '[email protected]', 
'username' => 'ruth'));
+        $type->addDocument($doc);
+
+        // Refresh index
+        $index->refresh();
+
+        $boost = 1.3;
+        $query_match = new MatchAll();
+
+        $query = new ConstantScore();
+        $query->setQuery($query_match);
+        $query->setBoost($boost);
+
+        $expectedArray = array(
+            'constant_score' => array(
+                'query' => $query_match->toArray(),
+                'boost' => $boost
+            )
+        );
+
+        $this->assertEquals($expectedArray, $query->toArray());
+        $resultSet = $type->search($query);
+
+        $results = $resultSet->getResults();
+
+        $this->assertEquals($resultSet->count(), 3);
+        $this->assertEquals($results[1]->getScore(), 1);
+
+    }
+
     public function testConstructEmpty()
     {
         $query = new ConstantScore();
diff --git a/Elastica/test/lib/Elastica/Test/Query/FilteredTest.php 
b/Elastica/test/lib/Elastica/Test/Query/FilteredTest.php
index 636b737..c6bd909 100644
--- a/Elastica/test/lib/Elastica/Test/Query/FilteredTest.php
+++ b/Elastica/test/lib/Elastica/Test/Query/FilteredTest.php
@@ -12,9 +12,7 @@
 {
     public function testFilteredSearch()
     {
-        $client = $this->_getClient();
-        $index = $client->getIndex('test');
-        $index->create(array(), true);
+        $index = $this->_createIndex();
         $type = $index->getType('helloworld');
 
         $doc = new Document(1, array('id' => 1, 'email' => '[email protected]', 
'username' => 'hanswurst', 'test' => array('2', '3', '5')));
@@ -62,4 +60,53 @@
         $this->assertEquals($query1->getFilter(), $filter1);
         $this->assertEquals($query2->getFilter(), $filter2);
     }
+
+    /**
+     * @expectedException \Elastica\Exception\InvalidException
+     */
+    public function testFilteredWithoutArgumentsShouldRaiseException()
+    {
+        $query = new Filtered();
+        $query->toArray();
+    }
+    
+    public function testFilteredSearchNoQuery()
+    {
+        $index = $this->_createIndex();
+        $type = $index->getType('helloworld');
+
+        $doc = new Document(1, array('id' => 1, 'email' => '[email protected]', 
'username' => 'hanswurst', 'test' => array('2', '3', '5')));
+        $type->addDocument($doc);
+        $doc = new Document(2, array('id' => 2, 'email' => '[email protected]', 
'username' => 'peter', 'test' => array('2', '3', '5')));
+        $type->addDocument($doc);
+
+        $filter = new Term();
+        $filter->setTerm('username', 'peter');
+
+        $query = new Filtered(null, $filter);
+        $index->refresh();
+
+        $resultSet = $type->search($query);
+        $this->assertEquals(1, $resultSet->count());
+    }
+    
+    public function testFilteredSearchNoFilter()
+    {
+        $index = $this->_createIndex();
+        $type = $index->getType('helloworld');
+
+        $doc = new Document(1, array('id' => 1, 'email' => '[email protected]', 
'username' => 'hanswurst', 'test' => array('2', '3', '5')));
+        $type->addDocument($doc);
+        $doc = new Document(2, array('id' => 2, 'email' => '[email protected]', 
'username' => 'peter', 'test' => array('2', '3', '5')));
+        $type->addDocument($doc);
+
+        $queryString = new QueryString('hans*');
+
+        $query = new Filtered($queryString);
+        $index->refresh();
+
+        $resultSet = $type->search($query);
+        $this->assertEquals(1, $resultSet->count());
+    }
+    
 }
diff --git a/Elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php 
b/Elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php
index cf6bb2e..47d9dd2 100755
--- a/Elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php
+++ b/Elastica/test/lib/Elastica/Test/Query/FunctionScoreTest.php
@@ -170,6 +170,16 @@
         $this->assertEquals("Miller's Field", $result0['name']);
     }
 
+    public function testRandomScoreWithoutSeed()
+    {
+        $query = new FunctionScore();
+        $query->setRandomScore();
+
+        $response = $this->type->search($query);
+
+        $this->assertEquals(2, $response->count());
+    }
+
     public function testScriptScore()
     {
         $scriptString = "_score * doc['price'].value";
diff --git a/Elastica/test/lib/Elastica/Test/Query/PostFilterTest.php 
b/Elastica/test/lib/Elastica/Test/Query/PostFilterTest.php
new file mode 100644
index 0000000..16b7e07
--- /dev/null
+++ b/Elastica/test/lib/Elastica/Test/Query/PostFilterTest.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Elastica\Test\Query;
+
+use Elastica\Document;
+use Elastica\Filter\Term;
+use Elastica\Index;
+use Elastica\Query\Match;
+use Elastica\Query;
+use Elastica\Test\Base as BaseTest;
+
+class PostFilterTest extends BaseTest
+{
+    /**
+     * @var Index
+     */
+    protected $_index;
+
+    protected function setUp()
+    {
+        parent::setUp();
+        $this->_index = $this->_createIndex("query");
+        $docs = array(
+            new Document("1", array("color" => "green", "make" => "ford")),
+            new Document("2", array("color" => "blue", "make" => "volvo")),
+            new Document("3", array("color" => "red", "make" => "ford")),
+            new Document("4", array("color" => "green", "make" => "renault")),
+        );
+        $this->_index->getType("test")->addDocuments($docs);
+        $this->_index->refresh();
+
+    }
+
+    protected function tearDown()
+    {
+        parent::tearDown();
+        if ($this->_index instanceof Index) {
+            $this->_index->delete();
+        }
+    }
+
+    public function testToArray()
+    {
+        $query = new Query();
+
+        $post_filter = new Term(array('color' => 'green'));
+        $query->setPostFilter($post_filter->toArray());
+
+        $data = $query->toArray();
+
+        $this->assertArrayHasKey('post_filter', $data);
+        $this->assertEquals(array('term' => array('color' => 'green')), 
$data['post_filter']);
+
+        $query->setPostFilter(array());
+
+        $this->assertArrayNotHasKey('post_filter', $query->toArray());
+    }
+
+    public function testQuery()
+    {
+        $query = new Query();
+
+        $match = new Match();
+        $match->setField('make', 'ford');
+
+        $query->setQuery($match);
+
+        $filter = new Term();
+        $filter->setTerm('color', 'green');
+
+        $query->setPostFilter($filter->toArray());
+
+        $results = $this->_index->search($query);
+
+        $this->assertEquals(1, $results->getTotalHits());
+
+    }
+
+    protected function _createIndex($name = 'test', $delete = true, $shards = 
1)
+    {
+        return parent::_createIndex('test_postfilter_' . $name, $delete, 
$shards);
+    }
+}
diff --git a/Elastica/test/lib/Elastica/Test/Transport/HttpTest.php 
b/Elastica/test/lib/Elastica/Test/Transport/HttpTest.php
index 2094682..88c93be 100644
--- a/Elastica/test/lib/Elastica/Test/Transport/HttpTest.php
+++ b/Elastica/test/lib/Elastica/Test/Transport/HttpTest.php
@@ -211,4 +211,17 @@
         $this->assertEquals(1, $resultSet->getTotalHits());
     }
 
+    public function testPostWith0Body()
+    {
+        $client = new Client();
+
+        $index = $client->getIndex('elastica_0_body');
+        $index->create(array(), true);
+        $index->refresh();
+
+        $tokens = $index->analyze('0');
+
+        $this->assertNotEmpty($tokens);
+    }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/159802
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9f85924ee9d792a8679554888e8cbf5913aa39c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Elastica
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to