Skip to content

Commit

Permalink
Merge pull request #50 from netgen/fix_build_on_32
Browse files Browse the repository at this point in the history
Update for eZ Platform 3.2
  • Loading branch information
pspanja committed Oct 22, 2020
2 parents d3e1d67 + 66a8f56 commit bf57e46
Show file tree
Hide file tree
Showing 17 changed files with 331 additions and 200 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Read the Docs](https://img.shields.io/readthedocs/pip.svg?style=flat-square)](https://netgen-ezplatform-search-extra.readthedocs.io/en/latest/index.html)
[![Downloads](https://img.shields.io/packagist/dt/netgen/ezplatform-search-extra.svg?style=flat-square)](https://packagist.org/packages/netgen/ezplatform-search-extra)
[![Latest stable](https://img.shields.io/github/release/netgen/ezplatform-search-extra.svg?style=flat-square)](https://packagist.org/packages/netgen/ezplatform-search-extra)
[![eZ](https://img.shields.io/badge/eZ%20Platform-%E2%89%A5%203.1-orange.svg?style=flat-square)](https://ezplatform.com/)
[![eZ](https://img.shields.io/badge/eZ%20Platform-%E2%89%A5%203.2-orange.svg?style=flat-square)](https://ezplatform.com/)
[![License](https://img.shields.io/github/license/netgen/ezplatform-search-extra.svg?style=flat-square)](https://packagist.org/packages/netgen/ezplatform-search-extra)

### Note: release compatible with eZ Platform v2 is `1.14`.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"ezsystems/ezplatform-kernel": "^1.1",
"ezsystems/ezplatform-kernel": "^1.2",
"ext-json": "*",
"ext-dom": "*"
},
Expand Down
23 changes: 19 additions & 4 deletions lib/Container/Compiler/SearchResultExtractorPass.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

declare(strict_types=1);

namespace Netgen\EzPlatformSearchExtra\Container\Compiler;

use Netgen\EzPlatformSearchExtra\Core\Search\Solr\ResultExtractor\NativeResultExtractor;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand All @@ -20,7 +21,7 @@ final class SearchResultExtractorPass implements CompilerPassInterface
*
* @throws \Exception
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$useLoadingSearchResultExtractor = $container->getParameter(
'netgen_ez_platform_search_extra.use_loading_search_result_extractor'
Expand All @@ -30,15 +31,29 @@ public function process(ContainerBuilder $container)
return;
}

$serviceId = 'netgen.search.solr.result_extractor.native_override';
$decoratedServiceId = 'ezpublish.search.solr.result_extractor.native';
$serviceId = 'netgen.search.solr.result_extractor.content.native_override';
$decoratedServiceId = 'ezpublish.search.solr.result_extractor.content.native';

$container
->register($serviceId, NativeResultExtractor::class)
->setDecoratedService($decoratedServiceId)
->setArguments([
new Reference($serviceId . '.inner'),
new Reference('ezpublish.search.solr.query.content.facet_builder_visitor.aggregate'),
new Reference('ezpublish.search.solr.query.content.aggregation_result_extractor.dispatcher'),
new Reference('ezpublish.search.solr.gateway.endpoint_registry'),
]);

$serviceId = 'netgen.search.solr.result_extractor.location.native_override';
$decoratedServiceId = 'ezpublish.search.solr.result_extractor.location.native';

$container
->register($serviceId, NativeResultExtractor::class)
->setDecoratedService($decoratedServiceId)
->setArguments([
new Reference($serviceId . '.inner'),
new Reference('ezpublish.search.solr.query.location.facet_builder_visitor.aggregate'),
new Reference('ezpublish.search.solr.query.location.aggregation_result_extractor.dispatcher'),
new Reference('ezpublish.search.solr.gateway.endpoint_registry'),
]);
}
Expand Down
35 changes: 24 additions & 11 deletions lib/Core/Pagination/Pagerfanta/BaseAdapter.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

declare(strict_types=1);

namespace Netgen\EzPlatformSearchExtra\Core\Pagination\Pagerfanta;

use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Search\AggregationResultCollection;
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;
use Netgen\EzPlatformSearchExtra\API\Values\Content\Search\SearchResult as ExtraSearchResult;
use Netgen\EzPlatformSearchExtra\API\Values\Content\Search\Suggestion;
Expand All @@ -14,9 +17,6 @@
*/
abstract class BaseAdapter implements AdapterInterface, SearchResultExtras
{
/**
* @var \eZ\Publish\API\Repository\Values\Content\Query
*/
private $query;

/**
Expand All @@ -29,6 +29,11 @@ abstract class BaseAdapter implements AdapterInterface, SearchResultExtras
*/
private $facets;

/**
* @var \eZ\Publish\API\Repository\Values\Content\Search\AggregationResultCollection
*/
private $aggregations;

/**
* @var float
*/
Expand Down Expand Up @@ -57,35 +62,42 @@ public function __construct(Query $query)
$this->query = $query;
}

public function getNbResults()
public function getNbResults(): int
{
$this->initializeExtraInfo();

return $this->nbResults;
}

public function getFacets()
public function getFacets(): array
{
$this->initializeExtraInfo();

return $this->facets;
}

public function getMaxScore()
public function getAggregations(): AggregationResultCollection
{
$this->initializeExtraInfo();

return $this->aggregations;
}

public function getMaxScore(): float
{
$this->initializeExtraInfo();

return $this->maxScore;
}

public function getSuggestion()
public function getSuggestion(): Suggestion
{
$this->initializeExtraInfo();

return $this->suggestion;
}

public function getTime()
public function getTime(): ?int
{
return $this->time;
}
Expand Down Expand Up @@ -115,9 +127,9 @@ public function getSlice($offset, $length)
*
* @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
*/
abstract protected function executeQuery(Query $query);
abstract protected function executeQuery(Query $query): SearchResult;

private function initializeExtraInfo()
private function initializeExtraInfo(): void
{
if ($this->isExtraInfoInitialized) {
return;
Expand All @@ -130,9 +142,10 @@ private function initializeExtraInfo()
$this->setExtraInfo($searchResult);
}

private function setExtraInfo(SearchResult $searchResult)
private function setExtraInfo(SearchResult $searchResult): void
{
$this->facets = $searchResult->facets;
$this->aggregations = $searchResult->aggregations;
$this->maxScore = $searchResult->maxScore;
$this->nbResults = $searchResult->totalCount;
$this->suggestion = new Suggestion([]);
Expand Down
8 changes: 4 additions & 4 deletions lib/Core/Pagination/Pagerfanta/SearchAdapter.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

declare(strict_types=1);

namespace Netgen\EzPlatformSearchExtra\Core\Pagination\Pagerfanta;

use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;

class SearchAdapter extends BaseAdapter
{
/**
* @var \eZ\Publish\API\Repository\SearchService
*/
private $searchService;

public function __construct(Query $query, SearchService $searchService)
Expand All @@ -25,7 +25,7 @@ public function __construct(Query $query, SearchService $searchService)
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
protected function executeQuery(Query $query)
protected function executeQuery(Query $query): SearchResult
{
if ($query instanceof LocationQuery) {
return $this->searchService->findLocations($query);
Expand Down
8 changes: 4 additions & 4 deletions lib/Core/Pagination/Pagerfanta/SearchHandlerAdapter.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

declare(strict_types=1);

namespace Netgen\EzPlatformSearchExtra\Core\Pagination\Pagerfanta;

use eZ\Publish\API\Repository\Values\Content\LocationQuery;
use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Search\SearchResult;
use eZ\Publish\SPI\Search\Handler as SearchHandlerInterface;

class SearchHandlerAdapter extends BaseAdapter
{
/**
* @var SearchHandlerInterface
*/
private $searchHandler;

public function __construct(Query $query, SearchHandlerInterface $searchHandler)
Expand All @@ -25,7 +25,7 @@ public function __construct(Query $query, SearchHandlerInterface $searchHandler)
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
protected function executeQuery(Query $query)
protected function executeQuery(Query $query): SearchResult
{
if ($query instanceof LocationQuery) {
return $this->searchHandler->findLocations($query);
Expand Down
8 changes: 5 additions & 3 deletions lib/Core/Pagination/Pagerfanta/Slice.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Netgen\EzPlatformSearchExtra\Core\Pagination\Pagerfanta;

use function array_key_exists;
Expand Down Expand Up @@ -42,7 +44,7 @@ static function (SearchHit $searchHit) {
);
}

public function offsetExists($offset)
public function offsetExists($offset): bool
{
return array_key_exists($offset, $this->searchHits);
}
Expand All @@ -52,12 +54,12 @@ public function offsetGet($offset)
return $this->searchHits[$offset]->valueObject;
}

public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
throw new RuntimeException('Method ' . __METHOD__ . ' is not supported');
}

public function offsetUnset($offset)
public function offsetUnset($offset): void
{
throw new RuntimeException('Method ' . __METHOD__ . ' is not supported');
}
Expand Down
14 changes: 8 additions & 6 deletions lib/Core/Pagination/SearchResultExtras.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

declare(strict_types=1);

namespace Netgen\EzPlatformSearchExtra\Core\Pagination;

use Netgen\EzPlatformSearchExtra\API\Values\Content\Search\Suggestion;

/**
* Defines access to extra information of the search query result.
*/
Expand All @@ -12,21 +16,19 @@ interface SearchResultExtras
*
* @return \eZ\Publish\API\Repository\Values\Content\Search\Facet[]
*/
public function getFacets();
public function getFacets(): array;

/**
* Return maximum score for the search query.
*
* @return float
*/
public function getMaxScore();
public function getMaxScore(): float;

/**
* Return suggestion object for the search query.
*
* @return \Netgen\EzPlatformSearchExtra\API\Values\Content\Search\Suggestion
*/
public function getSuggestion();
public function getSuggestion(): Suggestion;

/**
* Return duration of the search query processing in milliseconds.
Expand All @@ -35,5 +37,5 @@ public function getSuggestion();
*
* @return int|null
*/
public function getTime();
public function getTime(): ?int;
}

0 comments on commit bf57e46

Please sign in to comment.