-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MatchNone the inverse of MatchAll
This query is sometimes handy and I think Elastica should support it.
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace Elastica\Query; | ||
|
||
/** | ||
* Match none query. Returns no results. | ||
* | ||
* @author David Causse | ||
* | ||
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html#query-dsl-match-none-query | ||
*/ | ||
class MatchNone extends AbstractQuery | ||
{ | ||
/** | ||
* Creates match all query. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->_params = new \stdClass(); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
namespace Elastica\Test\Query; | ||
|
||
use Elastica\Document; | ||
use Elastica\Query\MatchNone; | ||
use Elastica\Search; | ||
use Elastica\Test\Base as BaseTest; | ||
|
||
class MatchNoneTest extends BaseTest | ||
{ | ||
/** | ||
* @group unit | ||
*/ | ||
public function testToArray() | ||
{ | ||
$query = new MatchNone(); | ||
|
||
$expectedArray = ['match_none' => new \stdClass()]; | ||
|
||
$this->assertEquals($expectedArray, $query->toArray()); | ||
} | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
public function testMatchNone() | ||
{ | ||
$index = $this->_createIndex(); | ||
$client = $index->getClient(); | ||
|
||
$doc = new Document(1, ['name' => 'ruflin']); | ||
$index->getType('test')->addDocument($doc); | ||
|
||
$index->refresh(); | ||
|
||
$search = new Search($client); | ||
$resultSet = $search->search(new MatchNone()); | ||
|
||
$this->assertEquals(0, $resultSet->getTotalHits()); | ||
} | ||
} |
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