Skip to content
Snippets Groups Projects
Commit e5ecc74f authored by Simonas Šerlinskas's avatar Simonas Šerlinskas
Browse files

Merge branch 'master' into docs

parents bbee2931 042fa88d
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
], ],
"require": { "require": {
"php": ">=5.4", "php": ">=5.4",
"symfony/serializer": "~2.7" "symfony/serializer": "~2.7",
"symfony/options-resolver": "~2.7"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~4.4", "phpunit/phpunit": "~4.4",
......
...@@ -15,11 +15,11 @@ use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; ...@@ -15,11 +15,11 @@ use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
use ONGR\ElasticsearchDSL\Highlight\Highlight; use ONGR\ElasticsearchDSL\Highlight\Highlight;
use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointFactory; use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointFactory;
use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointInterface; use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointInterface;
use ONGR\ElasticsearchDSL\Serializer\Normalizer\CustomReferencedNormalizer;
use ONGR\ElasticsearchDSL\Serializer\OrderedSerializer;
use ONGR\ElasticsearchDSL\Sort\AbstractSort; use ONGR\ElasticsearchDSL\Sort\AbstractSort;
use ONGR\ElasticsearchDSL\Sort\Sorts; use ONGR\ElasticsearchDSL\Sort\Sorts;
use ONGR\ElasticsearchDSL\Suggester\AbstractSuggester; use ONGR\ElasticsearchDSL\Suggester\AbstractSuggester;
use ONGR\ElasticsearchBundle\Serializer\Normalizer\CustomReferencedNormalizer;
use ONGR\ElasticsearchBundle\Serializer\OrderedSerializer;
use Symfony\Component\Serializer\Normalizer\CustomNormalizer; use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
/** /**
...@@ -550,34 +550,6 @@ class Search ...@@ -550,34 +550,6 @@ class Search
->getBuilder(); ->getBuilder();
} }
/**
* Adds suggester to search.
*
* @param AbstractSuggester $suggester
*
* @return Search
*/
public function addSuggester(AbstractSuggester $suggester)
{
$this
->getEndpoint('suggest')
->addBuilder($suggester);
return $this;
}
/**
* Returns all contained suggester's.
*
* @return AbstractSuggester[]
*/
public function getSuggesters()
{
return $this
->getEndpoint('suggest')
->getBuilder();
}
/** /**
* Setter for scroll duration, effectively setting if search is scrolled or not. * Setter for scroll duration, effectively setting if search is scrolled or not.
* *
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace ONGR\ElasticsearchDSL\SearchEndpoint; namespace ONGR\ElasticsearchDSL\SearchEndpoint;
use ONGR\ElasticsearchBundle\Serializer\Normalizer\AbstractNormalizable; use ONGR\ElasticsearchDSL\Serializer\Normalizer\AbstractNormalizable;
/** /**
* Abstract class used to define search endpoint with references. * Abstract class used to define search endpoint with references.
......
...@@ -15,7 +15,7 @@ use ONGR\ElasticsearchDSL\BuilderInterface; ...@@ -15,7 +15,7 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait; use ONGR\ElasticsearchDSL\ParametersTrait;
use ONGR\ElasticsearchDSL\Query\BoolQuery; use ONGR\ElasticsearchDSL\Query\BoolQuery;
use ONGR\ElasticsearchDSL\Query\FilteredQuery; use ONGR\ElasticsearchDSL\Query\FilteredQuery;
use ONGR\ElasticsearchBundle\Serializer\Normalizer\OrderedNormalizerInterface; use ONGR\ElasticsearchDSL\Serializer\Normalizer\OrderedNormalizerInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
......
<?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\Serializer\Normalizer;
use ONGR\ElasticsearchDSL\ParametersTrait;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;
/**
* Custom abstract normalizer which can save references for other objects.
*/
abstract class AbstractNormalizable implements NormalizableInterface
{
use ParametersTrait {
ParametersTrait::hasParameter as hasReference;
ParametersTrait::getParameter as getReference;
ParametersTrait::getParameters as getReferences;
ParametersTrait::addParameter as addReference;
ParametersTrait::setParameters as setReferences;
}
}
<?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\Serializer\Normalizer;
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
/**
* Normalizer used with referenced normalized objects.
*/
class CustomReferencedNormalizer extends CustomNormalizer
{
/**
* @var array
*/
private $references = [];
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = [])
{
$object->setReferences($this->references);
$data = parent::normalize($object, $format, $context);
$this->references = array_merge($this->references, $object->getReferences());
return $data;
}
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
{
return $data instanceof AbstractNormalizable;
}
}
<?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\Serializer\Normalizer;
/**
* This should be implemented by normalizable object that required to be processed in specific order.
*/
interface OrderedNormalizerInterface
{
/**
* Returns normalization priority.
*
* @return int
*/
public function getOrder();
}
<?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\Serializer;
use ONGR\ElasticsearchDSL\Serializer\Normalizer\OrderedNormalizerInterface;
use Symfony\Component\Serializer\Serializer;
/**
* Custom serializer which orders data before normalization.
*/
class OrderedSerializer extends Serializer
{
/**
* {@inheritdoc}
*/
public function normalize($data, $format = null, array $context = [])
{
return parent::normalize(
is_array($data) ? $this->order($data) : $data,
$format,
$context
);
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $type, $format = null, array $context = [])
{
return parent::denormalize(
is_array($data) ? $this->order($data) : $data,
$type,
$format,
$context
);
}
/**
* Orders objects if can be done.
*
* @param array $data Data to order.
*
* @return array
*/
private function order(array $data)
{
$filteredData = $this->filterOrderable($data);
if (!empty($filteredData)) {
uasort(
$filteredData,
function (OrderedNormalizerInterface $a, OrderedNormalizerInterface $b) {
return $a->getOrder() > $b->getOrder();
}
);
return array_merge($filteredData, array_diff_key($data, $filteredData));
}
return $data;
}
/**
* Filters out data which can be ordered.
*
* @param array $array Data to filter out.
*
* @return array
*/
private function filterOrderable($array)
{
return array_filter(
$array,
function ($value) {
return $value instanceof OrderedNormalizerInterface;
}
);
}
}
<?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\SearchEndpoint;
use ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint;
/**
* Unit test class for the QueryEndpoint.
*/
class QueryEndpointTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests constructor.
*/
public function testItCanBeInstantiated()
{
$this->assertInstanceOf('ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint', new QueryEndpoint());
}
}
<?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\DSL;
use ONGR\ElasticsearchDSL\Search;
/**
* Test for Search.
*/
class SearchTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests Search constructor.
*/
public function testItCanBeInstantiated()
{
$this->assertInstanceOf('ONGR\ElasticsearchDSL\Search', new Search());
}
}
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