Skip to content
Snippets Groups Projects
Commit 2259f649 authored by KnysakPatryk's avatar KnysakPatryk Committed by Simonas Šerlinskas
Browse files

Removed deprecated queries (#182)

parent 076de611
No related branches found
No related tags found
No related merge requests found
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
/**
* Represents Elasticsearch "limit" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-limit-query.html
*/
class LimitQuery implements BuilderInterface
{
/**
* @var int
*/
private $value;
/**
* @param int $value Number of documents (per shard) to execute on
*/
public function __construct($value)
{
$this->value = $value;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'limit';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
return [
$this->getType() => [
'value' => $this->value,
],
];
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "missing" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-missing-query.html
*/
class MissingQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var string
*/
private $field;
/**
* Constructor.
*
* @param string $field Field name
* @param array $parameters Optional parameters
*/
public function __construct($field, array $parameters = [])
{
$this->field = $field;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'missing';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = ['field' => $this->field];
$output = $this->processArray($query);
return [$this->getType() => $output];
}
}
......@@ -14,8 +14,8 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation;
use ONGR\ElasticsearchDSL\Aggregation\FilterAggregation;
use ONGR\ElasticsearchDSL\Aggregation\HistogramAggregation;
use ONGR\ElasticsearchDSL\Query\BoolQuery;
use ONGR\ElasticsearchDSL\Query\ExistsQuery;
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
use ONGR\ElasticsearchDSL\Query\MissingQuery;
use ONGR\ElasticsearchDSL\Query\TermQuery;
class FilterAggregationTest extends \PHPUnit_Framework_TestCase
......@@ -130,7 +130,7 @@ class FilterAggregationTest extends \PHPUnit_Framework_TestCase
{
$aggregation = new FilterAggregation('test_agg');
$aggregation->setFilter(new MissingQuery('test'));
$aggregation->setFilter(new ExistsQuery('test'));
$aggregation->toArray();
}
......
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Tests\Unit\Query;
use ONGR\ElasticsearchDSL\Query\LimitQuery;
class LimitQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Test for query toArray() method.
*/
public function testToArray()
{
$query = new LimitQuery(3);
$expectedResult = [
'limit' => ['value' => 3]
];
$this->assertEquals($expectedResult, $query->toArray());
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Tests\Unit\Query;
use ONGR\ElasticsearchDSL\Query\MissingQuery;
class MissingQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Data provider to testGetToArray.
*
* @return array
*/
public function getArrayDataProvider()
{
return [
// Case 1.
['user', [], ['field' => 'user']],
// Case 2.
['user', ['existence' => true], ['field' => 'user', 'existence' => true]],
];
}
/**
* Test for query toArray() method.
*
* @param string $field
* @param array $parameters
* @param array $expected
*
* @dataProvider getArrayDataProvider
*/
public function testToArray($field, $parameters, $expected)
{
$query = new MissingQuery($field, $parameters);
$result = $query->toArray();
$this->assertEquals(['missing' => $expected], $result);
}
}
......@@ -11,7 +11,7 @@
namespace ONGR\ElasticsearchDSL\Tests\Unit;
use ONGR\ElasticsearchDSL\Query\MissingQuery;
use ONGR\ElasticsearchDSL\Query\ExistsQuery;
use ONGR\ElasticsearchDSL\Query\TermQuery;
use ONGR\ElasticsearchDSL\Search;
use ONGR\ElasticsearchDSL\Sort\FieldSort;
......@@ -235,13 +235,13 @@ class SearchTest extends \PHPUnit_Framework_TestCase
],
'filter' => [
[
'missing' => ['field' => 'baz'],
'exists' => ['field' => 'baz'],
],
],
],
],
],
(new Search())->addQuery(new TermQuery('foo', 'bar'))->addFilter(new MissingQuery('baz')),
(new Search())->addQuery(new TermQuery('foo', 'bar'))->addFilter(new ExistsQuery('baz')),
];
$cases['sort_by_price'] = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment