-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring aggregation to be compliant with Elasticsuite 2.8
- Loading branch information
1 parent
29780ee
commit 9b09810
Showing
6 changed files
with
177 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Plugin/Search/Request/Product/Attribute/AggregationResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteRating | ||
* @author Romain Ruaud <[email protected]> | ||
* @copyright 2019 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticsuiteRating\Plugin\Search\Request\Product\Attribute; | ||
|
||
/** | ||
* Plugin to set aggregation builder for ratings. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteRating | ||
* @author Romain Ruaud <[email protected]> | ||
*/ | ||
class AggregationResolver | ||
{ | ||
/** | ||
* Rating Summary attribute code. | ||
*/ | ||
const RATING_SUMMARY_ATTRIBUTE = 'ratings_summary'; | ||
|
||
/** | ||
* @var \Smile\ElasticsuiteRating\Search\Request\Product\Attribute\Aggregation\Rating | ||
*/ | ||
private $ratingAggregation; | ||
|
||
/** | ||
* AggregationResolver constructor. | ||
* | ||
* @param \Smile\ElasticsuiteRating\Search\Request\Product\Attribute\Aggregation\Rating $ratingAggregation Rating Aggregation | ||
*/ | ||
public function __construct(\Smile\ElasticsuiteRating\Search\Request\Product\Attribute\Aggregation\Rating $ratingAggregation) | ||
{ | ||
$this->ratingAggregation = $ratingAggregation; | ||
} | ||
|
||
/** | ||
* Set default facet size to 0 for swatches attributes before adding it as aggregation. | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
* | ||
* @param \Smile\ElasticsuiteCatalog\Search\Request\Product\Attribute\AggregationResolver $subject Aggregation Resolver | ||
* @param array $result Aggregation Config | ||
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute Attribute | ||
* | ||
* @return array | ||
*/ | ||
public function afterGetAggregationData( | ||
\Smile\ElasticsuiteCatalog\Search\Request\Product\Attribute\AggregationResolver $subject, | ||
$result, | ||
$attribute | ||
) { | ||
if ($attribute->getAttributeCode() === self::RATING_SUMMARY_ATTRIBUTE) { | ||
$result = $this->ratingAggregation->getAggregationData($attribute); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteRating | ||
* @author Romain Ruaud <[email protected]> | ||
* @copyright 2019 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteRating\Search\Request\Product\Attribute\Aggregation; | ||
|
||
use Smile\ElasticsuiteCatalog\Search\Request\Product\Attribute\AggregationInterface; | ||
use Smile\ElasticsuiteCore\Search\Request\BucketInterface; | ||
|
||
/** | ||
* Aggregation builder for product ratings. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteRating | ||
* @author Romain Ruaud <[email protected]> | ||
*/ | ||
class Rating implements AggregationInterface | ||
{ | ||
/** | ||
* Default interval, based on 0-100 divided in five stars. | ||
*/ | ||
const RATING_AGG_INTERVAL = 20; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getAggregationData(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute) | ||
{ | ||
$bucketConfig = [ | ||
'name' => $this->getFilterField($attribute), | ||
'type' => BucketInterface::TYPE_HISTOGRAM, | ||
'minDocCount' => 1, | ||
'interval' => (int) self::RATING_AGG_INTERVAL, | ||
]; | ||
|
||
return $bucketConfig; | ||
} | ||
|
||
/** | ||
* Retrieve ES filter field. | ||
* | ||
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute Attribute | ||
* | ||
* @return string | ||
*/ | ||
private function getFilterField(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute) | ||
{ | ||
$field = $attribute->getAttributeCode(); | ||
|
||
return $field; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Smile_ElasticsuiteCatalog dependency injection configuration. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteRating | ||
* @author Romain Ruaud <[email protected]> | ||
* @copyright 2019 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
|
||
<!-- Datasources resolver --> | ||
<type name="Smile\ElasticsuiteCore\Index\DataSourceResolver"> | ||
<arguments> | ||
<argument name="datasources" xsi:type="array"> | ||
<item name="catalog_product" xsi:type="array"> | ||
<item name="rating" xsi:type="object">Smile\ElasticsuiteRating\Model\Product\Indexer\Fulltext\Datasource\RatingData</item> | ||
</item> | ||
</argument> | ||
</arguments> | ||
</type> | ||
|
||
<type name="\Smile\ElasticsuiteCatalog\Search\Request\Product\Attribute\AggregationResolver"> | ||
<plugin name="rating_aggregation" type="Smile\ElasticsuiteRating\Plugin\Search\Request\Product\Attribute\AggregationResolver"/> | ||
</type> | ||
|
||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters