Skip to content
Snippets Groups Projects
Commit f93b3c25 authored by Mantas Varatiejus's avatar Mantas Varatiejus
Browse files

Cover query classes with tests

parent ef160e57
No related branches found
No related tags found
No related merge requests found
Showing
with 272 additions and 19 deletions
......@@ -14,7 +14,9 @@ namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
/**
* Elasticsearch boosting query class.
* Represents Elasticsearch "boosting" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
*/
class BoostingQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Common terms query class.
* Represents Elasticsearch "common" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
*/
class CommonTermsQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Constant score query class.
* Represents Elasticsearch "constant_score" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html
*/
class ConstantScoreQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch dis max query class.
* Represents Elasticsearch "dis_max" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html
*/
class DisMaxQuery implements BuilderInterface
{
......@@ -65,7 +67,7 @@ class DisMaxQuery implements BuilderInterface
{
$query = [];
foreach ($this->queries as $type) {
$query = array_merge($query, $type->toArray());
$query[] = $type->toArray();
}
$output = $this->processArray(['queries' => $query]);
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch fuzzy query class.
* Represents Elasticsearch "fuzzy" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
*/
class FuzzyQuery implements BuilderInterface
{
......
......@@ -18,6 +18,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
* Represents Elasticsearch "ids" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html
*
* @todo Add "type" support
*/
class IdsQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch match query class.
* Represents Elasticsearch "match" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
*/
class MatchQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch more_like_this query class.
* Represents Elasticsearch "more_like_this" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html
*/
class MoreLikeThisQuery implements BuilderInterface
{
......@@ -24,15 +26,15 @@ class MoreLikeThisQuery implements BuilderInterface
/**
* @var string The text to find documents like it, required if ids or docs are not specified.
*/
private $likeText;
private $like;
/**
* @param string $likeText
* @param string $like
* @param array $parameters
*/
public function __construct($likeText, array $parameters = [])
public function __construct($like, array $parameters = [])
{
$this->likeText = $likeText;
$this->like = $like;
$this->setParameters($parameters);
}
......@@ -52,7 +54,7 @@ class MoreLikeThisQuery implements BuilderInterface
$query = [];
if (($this->hasParameter('ids') === false) || ($this->hasParameter('docs') === false)) {
$query['like_text'] = $this->likeText;
$query['like'] = $this->like;
}
$output = $this->processArray($query);
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch multi_match query class.
* Represents Elasticsearch "multi_match" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
*/
class MultiMatchQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch query_string query class.
* Represents Elasticsearch "query_string" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
*/
class QueryStringQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Range query class.
* Represents Elasticsearch "range" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
*/
class RangeQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch simple_query_string query class.
* Represents Elasticsearch "simple_query_string" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html
*/
class SimpleQueryStringQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch wildcard query class.
* Represents Elasticsearch "wildcard" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html
*/
class WildcardQuery implements BuilderInterface
{
......
......@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Tests\Aggregation;
namespace ONGR\ElasticsearchDSL\Tests\Query;
use ONGR\ElasticsearchDSL\Query\BoolQuery;
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
......
<?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\Query;
use ONGR\ElasticsearchDSL\Query\BoostingQuery;
class BoostingQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests toArray().
*/
public function testToArray()
{
$mock = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface');
$mock
->expects($this->any())
->method('toArray')
->willReturn(['term' => ['foo' => 'bar']]);
$query = new BoostingQuery($mock, $mock, 0.2);
$expected = [
'boosting' => [
'positive' => ['term' => ['foo' => 'bar']],
'negative' => ['term' => ['foo' => 'bar']],
'negative_boost' => 0.2,
],
];
$this->assertEquals($expected, $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\Query;
use ONGR\ElasticsearchDSL\Query\CommonTermsQuery;
class CommonTermsQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests toArray().
*/
public function testToArray()
{
$query = new CommonTermsQuery('body', 'this is bonsai cool', ['cutoff_frequency' => 0.01]);
$expected = [
'common' => [
'body' => [
'query' => 'this is bonsai cool',
'cutoff_frequency' => 0.01,
],
],
];
$this->assertEquals($expected, $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\Query;
use ONGR\ElasticsearchDSL\Query\ConstantScoreQuery;
class ConstantScoreQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests toArray().
*/
public function testToArray()
{
$mock = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface');
$mock
->expects($this->any())
->method('toArray')
->willReturn(['term' => ['foo' => 'bar']]);
$query = new ConstantScoreQuery($mock, ['boost' => 1.2]);
$expected = [
'constant_score' => [
'filter' => [
'term' => ['foo' => 'bar']
],
'boost' => 1.2,
],
];
$this->assertEquals($expected, $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\Query;
use ONGR\ElasticsearchDSL\Query\DisMaxQuery;
class DisMaxQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests toArray().
*/
public function testToArray()
{
$mock = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface');
$mock
->expects($this->any())
->method('toArray')
->willReturn(['term' => ['foo' => 'bar']]);
$query = new DisMaxQuery(['boost' => 1.2]);
$query->addQuery($mock);
$query->addQuery($mock);
$expected = [
'dis_max' => [
'queries' => [
['term' => ['foo' => 'bar']],
['term' => ['foo' => 'bar']],
],
'boost' => 1.2,
],
];
$this->assertEquals($expected, $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\Query;
use ONGR\ElasticsearchDSL\Query\FuzzyQuery;
class FuzzyQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests toArray().
*/
public function testToArray()
{
$query = new FuzzyQuery('user', 'ki', ['boost' => 1.2]);
$expected = [
'fuzzy' => [
'user' => [
'value' => 'ki',
'boost' => 1.2,
],
],
];
$this->assertEquals($expected, $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\Query;
use ONGR\ElasticsearchDSL\Query\IdsQuery;
class IdsQueryTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests toArray().
*/
public function testToArray()
{
$query = new IdsQuery(['foo', 'bar']);
$expected = [
'ids' => [
'values' => ['foo', 'bar'],
],
];
$this->assertEquals($expected, $query->toArray());
}
}
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