-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix tests * Improve docker files by removing --prefer-source as it is an automatic fallback now
- Loading branch information
Showing
14 changed files
with
321 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
namespace Elastica\Filter; | ||
|
||
use Elastica\Query\AbstractQuery; | ||
|
||
/** | ||
* Nested filter. | ||
* | ||
* @author Nicolas Ruflin <spam@ruflin.com> | ||
* | ||
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html | ||
*/ | ||
class Nested extends AbstractFilter | ||
{ | ||
/** | ||
* Adds field to mlt filter. | ||
* | ||
* @param string $path Nested object path | ||
* | ||
* @return $this | ||
*/ | ||
public function setPath($path) | ||
{ | ||
return $this->setParam('path', $path); | ||
} | ||
|
||
/** | ||
* Sets nested query. | ||
* | ||
* @param \Elastica\Query\AbstractQuery $query | ||
* | ||
* @return $this | ||
*/ | ||
public function setQuery(AbstractQuery $query) | ||
{ | ||
return $this->setParam('query', $query); | ||
} | ||
|
||
/** | ||
* Sets nested filter. | ||
* | ||
* @param \Elastica\Filter\AbstractFilter $filter | ||
* | ||
* @return $this | ||
*/ | ||
public function setFilter(AbstractFilter $filter) | ||
{ | ||
return $this->setParam('filter', $filter); | ||
} | ||
|
||
/** | ||
* Set join option. | ||
* | ||
* @param bool $join | ||
* | ||
* @return $this | ||
*/ | ||
public function setJoin($join) | ||
{ | ||
return $this->setParam('join', (bool) $join); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
test/lib/Elastica/Test/Filter/NestedFilterWithSetFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
namespace Elastica\Test\Filter; | ||
|
||
use Elastica\Document; | ||
use Elastica\Filter\Nested; | ||
use Elastica\Filter\Terms; | ||
use Elastica\Search; | ||
use Elastica\Test\Base as BaseTest; | ||
use Elastica\Type\Mapping; | ||
|
||
class NestedFilterWithSetFilterTest extends BaseTest | ||
{ | ||
protected function _getIndexForTest() | ||
{ | ||
$index = $this->_createIndex(); | ||
$type = $index->getType('user'); | ||
|
||
$type->setMapping(new Mapping(null, array( | ||
'firstname' => array('type' => 'string', 'store' => 'yes'), | ||
// default is store => no expected | ||
'lastname' => array('type' => 'string'), | ||
'hobbies' => array( | ||
'type' => 'nested', | ||
'include_in_parent' => true, | ||
'properties' => array('hobby' => array('type' => 'string')), | ||
), | ||
))); | ||
|
||
$type->addDocuments(array( | ||
new Document(1, array( | ||
'firstname' => 'Nicolas', | ||
'lastname' => 'Ruflin', | ||
'hobbies' => array( | ||
array('hobby' => 'opensource'), | ||
), | ||
)), | ||
new Document(2, array( | ||
'firstname' => 'Nicolas', | ||
'lastname' => 'Ippolito', | ||
'hobbies' => array( | ||
array('hobby' => 'opensource'), | ||
array('hobby' => 'guitar'), | ||
), | ||
)), | ||
)); | ||
|
||
$index->refresh(); | ||
|
||
return $index; | ||
} | ||
|
||
/** | ||
* @group unit | ||
*/ | ||
public function testToArray() | ||
{ | ||
$filter = new Nested(); | ||
$this->assertEquals(array('nested' => array()), $filter->toArray()); | ||
$query = new Terms(); | ||
$query->setTerms('hobby', array('guitar')); | ||
$filter->setPath('hobbies'); | ||
$filter->setFilter($query); | ||
|
||
$expectedArray = array( | ||
'nested' => array( | ||
'path' => 'hobbies', | ||
'filter' => array('terms' => array( | ||
'hobby' => array('guitar'), | ||
)), | ||
), | ||
); | ||
|
||
$this->assertEquals($expectedArray, $filter->toArray()); | ||
} | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
public function testShouldReturnTheRightNumberOfResult() | ||
{ | ||
$filter = new Nested(); | ||
$this->assertEquals(array('nested' => array()), $filter->toArray()); | ||
$query = new Terms(); | ||
$query->setTerms('hobbies.hobby', array('guitar')); | ||
$filter->setPath('hobbies'); | ||
$filter->setFilter($query); | ||
|
||
$client = $this->_getClient(); | ||
$search = new Search($client); | ||
$index = $this->_getIndexForTest(); | ||
$search->addIndex($index); | ||
$resultSet = $search->search($filter); | ||
|
||
$this->assertEquals(1, $resultSet->getTotalHits()); | ||
|
||
$filter = new Nested(); | ||
$this->assertEquals(array('nested' => array()), $filter->toArray()); | ||
$query = new Terms(); | ||
$query->setTerms('hobbies.hobby', array('opensource')); | ||
$filter->setPath('hobbies'); | ||
$filter->setFilter($query); | ||
|
||
$client = $this->_getClient(); | ||
$search = new Search($client); | ||
$index = $this->_getIndexForTest(); | ||
$search->addIndex($index); | ||
$resultSet = $search->search($filter); | ||
|
||
$this->assertEquals(2, $resultSet->getTotalHits()); | ||
} | ||
} |
Oops, something went wrong.