summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php')
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php103
1 files changed, 87 insertions, 16 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php
index 4396ceb4..87842b0f 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/RescoreTest.php
@@ -1,27 +1,17 @@
<?php
-
namespace Elastica\Test\Query;
-use Elastica\Rescore\Query as QueryRescore;
-use Elastica\Query\Term;
-use Elastica\Query\Match;
use Elastica\Query;
+use Elastica\Query\Match;
+use Elastica\Query\Term;
+use Elastica\Rescore\Query as QueryRescore;
use Elastica\Test\Base as BaseTest;
class RescoreTest extends BaseTest
{
/**
- * @var Index
+ * @group unit
*/
- protected $_index;
-
- protected function setUp()
- {
- parent::setUp();
- $this->_index = $this->_createIndex("rescore_test");
- $this->_index->refresh();
- }
-
public function testToArray()
{
$query = new Query();
@@ -59,6 +49,9 @@ class RescoreTest extends BaseTest
$this->assertEquals($expected, $data);
}
+ /**
+ * @group unit
+ */
public function testSetSize()
{
$query = new Query();
@@ -98,6 +91,9 @@ class RescoreTest extends BaseTest
$this->assertEquals($expected, $data);
}
+ /**
+ * @group unit
+ */
public function testSetWeights()
{
$query = new Query();
@@ -133,7 +129,7 @@ class RescoreTest extends BaseTest
),
),
'query_weight' => 0.7,
- 'rescore_query_weight' => 1.2
+ 'rescore_query_weight' => 1.2,
),
),
);
@@ -141,6 +137,79 @@ class RescoreTest extends BaseTest
$this->assertEquals($expected, $data);
}
+ /**
+ * @group functional
+ */
+ public function testMultipleQueries()
+ {
+ $query = new Query();
+ $mainQuery = new Match();
+ $mainQuery = $mainQuery->setFieldQuery('test1', 'foo');
+
+ $secQuery1 = new Term();
+ $secQuery1 = $secQuery1->setTerm('test2', 'bar', 1);
+ $rescoreQuery1 = new QueryRescore();
+ $rescoreQuery1->setRescoreQuery($secQuery1);
+
+ $secQuery2 = new Term();
+ $secQuery2 = $secQuery2->setTerm('test2', 'tom', 2);
+ $rescoreQuery2 = new QueryRescore();
+ $rescoreQuery2->setRescoreQuery($secQuery2);
+
+ $query->setQuery($mainQuery);
+ $query->setRescore(array($rescoreQuery1, $rescoreQuery2));
+ $data = $query->toArray();
+
+ $expected = array(
+ 'query' => array(
+ 'match' => array(
+ 'test1' => array(
+ 'query' => 'foo',
+ ),
+ ),
+ ),
+ 'rescore' => array(
+ array(
+ 'query' => array(
+ 'rescore_query' => array(
+ 'term' => array(
+ 'test2' => array(
+ 'value' => 'bar',
+ 'boost' => 1,
+ ),
+ ),
+ ),
+ ),
+ ),
+ array(
+ 'query' => array(
+ 'rescore_query' => array(
+ 'term' => array(
+ 'test2' => array(
+ 'value' => 'tom',
+ 'boost' => 2,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertEquals($expected, $data);
+
+ $index = $this->_createIndex();
+ $index->refresh();
+ $results = $index->search($query);
+ $response = $results->getResponse();
+
+ $this->assertEquals(true, $response->isOk());
+ $this->assertEquals(0, $results->getTotalHits());
+ }
+
+ /**
+ * @group functional
+ */
public function testQuery()
{
$query = new Query();
@@ -156,7 +225,9 @@ class RescoreTest extends BaseTest
$query->setRescore($queryRescore);
$data = $query->toArray();
- $results = $this->_index->search($query);
+ $index = $this->_createIndex();
+ $index->refresh();
+ $results = $index->search($query);
$response = $results->getResponse();
$this->assertEquals(true, $response->isOk());