Skip to content
Snippets Groups Projects
Commit 7a5541e1 authored by Mantas Marcinkevicius's avatar Mantas Marcinkevicius
Browse files

added inner hit endpoint

parent 5fe4dca5
No related branches found
No related tags found
No related merge requests found
......@@ -13,11 +13,13 @@ namespace ONGR\ElasticsearchDSL;
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
use ONGR\ElasticsearchDSL\Highlight\Highlight;
use ONGR\ElasticsearchDSL\InnerHit\AbstractInnerHit;
use ONGR\ElasticsearchDSL\Query\BoolQuery;
use ONGR\ElasticsearchDSL\SearchEndpoint\AbstractSearchEndpoint;
use ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint;
use ONGR\ElasticsearchDSL\SearchEndpoint\FilterEndpoint;
use ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint;
use ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint;
use ONGR\ElasticsearchDSL\SearchEndpoint\PostFilterEndpoint;
use ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint;
use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointFactory;
......@@ -328,6 +330,30 @@ class Search
return $this->getEndpoint(AggregationsEndpoint::NAME)->getAll();
}
/**
* Adds inner hit into search.
*
* @param AbstractInnerHit $innerHit
*
* @return $this
*/
public function addInnerHit(AbstractInnerHit $innerHit)
{
$this->getEndpoint(InnerHitsEndpoint::NAME)->add($innerHit, $innerHit->getName());
return $this;
}
/**
* Returns all inner hits.
*
* @return BuilderInterface[]
*/
public function getInnerHits()
{
return $this->getEndpoint(InnerHitsEndpoint::NAME)->getAll();
}
/**
* Adds sort to search.
*
......
<?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\SearchEndpoint;
use ONGR\ElasticsearchDSL\InnerHit\AbstractInnerHit;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Search inner hits dsl endpoint.
*/
class InnerHitsEndpoint extends AbstractSearchEndpoint
{
/**
* Endpoint name
*/
const NAME = 'inner_hits';
/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
{
$output = [];
if (count($this->getAll()) > 0) {
/** @var AbstractInnerHit $innerHit */
foreach ($this->getAll() as $innerHit) {
$output[$innerHit->getName()] = $innerHit->toArray();
}
}
return $output;
}
}
......@@ -27,6 +27,7 @@ class SearchEndpointFactory
'highlight' => 'ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint',
'aggregations' => 'ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint',
'suggest' => 'ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint',
'inner_hits' => 'ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint',
];
/**
......
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