1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Client\FactFinderNg\Plugin\ElasticSearch\ResultFormatter; |
9
|
|
|
|
10
|
|
|
use Elastica\ResultSet; |
11
|
|
|
use Generated\Shared\Transfer\SortSearchResultTransfer; |
|
|
|
|
12
|
|
|
use Spryker\Client\Search\Plugin\Elasticsearch\ResultFormatter\AbstractElasticsearchResultFormatterPlugin; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @method \SprykerEco\Client\FactFinderNg\FactFinderNgFactory getFactory() |
16
|
|
|
*/ |
17
|
|
|
class FactFinderSortedResultFormatterPlugin extends AbstractElasticsearchResultFormatterPlugin |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
public const NAME = 'sort'; |
20
|
|
|
public const SORT_ITEMS = 'sortItems'; |
21
|
|
|
public const KEY_NAME = 'name'; |
22
|
|
|
public const KEY_ORDER = 'order'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritDoc} |
26
|
|
|
* |
27
|
|
|
* @api |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function getName(): string |
32
|
|
|
{ |
33
|
|
|
return static::NAME; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param \Elastica\ResultSet $searchResult |
38
|
|
|
* @param array $requestParameters |
39
|
|
|
* |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
|
|
protected function formatSearchResult(ResultSet $searchResult, array $requestParameters) |
43
|
|
|
{ |
44
|
|
|
$sortSearchResultTransfer = new SortSearchResultTransfer(); |
45
|
|
|
$sortSearchResultTransfer |
46
|
|
|
->setSortParamNames($this->mapSortParamNames($searchResult->getResponse()->getData()[static::SORT_ITEMS] ?? [])) |
47
|
|
|
->setCurrentSortParam($this->getCurrentSortParam($requestParameters)); |
48
|
|
|
|
49
|
|
|
return $sortSearchResultTransfer; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $sortItems |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
protected function mapSortParamNames(array $sortItems): array |
58
|
|
|
{ |
59
|
|
|
$paramNames = []; |
60
|
|
|
|
61
|
|
|
foreach ($sortItems as $item) { |
62
|
|
|
$paramNames[] = sprintf('%s_%s', mb_strtolower($item[static::KEY_NAME]), $item[static::KEY_ORDER]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $paramNames; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param array $requestParameters |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
protected function getCurrentSortParam(array $requestParameters): string |
74
|
|
|
{ |
75
|
|
|
return $requestParameters[static::NAME] ?? ''; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths