84 private $queryContainer;
121 $this->queryContainer = $queryContainer;
130 return $this->range->getPriceRange();
146 $query = $this->getBasicSearchQuery($entityStorage);
148 $fieldName = $this->fieldMapper->getFieldName(
'price');
149 $query[
'body'][
'aggregations'] = [
151 'extended_stats' => [
152 'field' => $fieldName,
157 $queryResult = $this->connectionManager->getConnection()
160 if (isset($queryResult[
'aggregations'][
'prices'])) {
162 'count' => $queryResult[
'aggregations'][
'prices'][
'count'],
163 'max' => $queryResult[
'aggregations'][
'prices'][
'max'],
164 'min' => $queryResult[
'aggregations'][
'prices'][
'min'],
165 'std' => $queryResult[
'aggregations'][
'prices'][
'std_deviation'],
169 return $aggregations;
177 \
Magento\Framework\Search\Request\BucketInterface $bucket,
179 \
Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
181 $entityIds = $entityStorage->getSource();
182 $fieldName = $this->fieldMapper->getFieldName(
'price');
183 $dimension = current($dimensions);
184 $storeId = $this->scopeResolver->getScope($dimension->getValue())->getId();
186 return $this->intervalFactory->create(
188 'entityIds' => $entityIds,
190 'fieldName' => $fieldName,
200 \
Magento\Framework\Search\Request\BucketInterface $bucket,
203 \
Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
207 $query = $this->getBasicSearchQuery($entityStorage);
209 $fieldName = $this->fieldMapper->getFieldName($bucket->getField());
210 $query[
'body'][
'aggregations'] = [
213 'field' => $fieldName,
214 'interval' => (float)
$range,
219 $queryResult = $this->connectionManager->getConnection()
221 foreach ($queryResult[
'aggregations'][
'prices'][
'buckets'] as $bucket) {
222 $key = intval($bucket[
'key'] /
$range + 1);
223 $result[$key] = $bucket[
'doc_count'];
236 if (!empty($dbRanges)) {
237 $lastIndex = array_keys($dbRanges);
238 $lastIndex = $lastIndex[count($lastIndex) - 1];
243 'from' => $fromPrice,
270 private function getBasicSearchQuery(
271 \
Magento\Framework\Search\Dynamic\EntityStorage $entityStorage,
272 array $dimensions = []
274 if (
null !== $this->queryContainer) {
275 return $this->queryContainer->getQuery();
278 $entityIds = $entityStorage->getSource();
280 $dimension = current($dimensions);
282 ? $this->scopeResolver->getScope($dimension->getValue())->getId()
283 : $this->storeManager->getStore()->getId();
286 'index' => $this->searchIndexNameResolver->getIndexName(
$storeId, $this->indexerId),
287 'type' => $this->clientConfig->getEntityType(),
prepareData($range, array $dbRanges)
getAggregations(\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage)
getInterval(\Magento\Framework\Search\Request\BucketInterface $bucket, array $dimensions, \Magento\Framework\Search\Dynamic\EntityStorage $entityStorage)
getAggregation(\Magento\Framework\Search\Request\BucketInterface $bucket, array $dimensions, $range, \Magento\Framework\Search\Dynamic\EntityStorage $entityStorage)
__construct(\Magento\Elasticsearch\SearchAdapter\ConnectionManager $connectionManager, \Magento\Elasticsearch\Model\Adapter\FieldMapperInterface $fieldMapper, \Magento\Catalog\Model\Layer\Filter\Price\Range $range, \Magento\Framework\Search\Dynamic\IntervalFactory $intervalFactory, \Magento\Elasticsearch\Model\Config $clientConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Elasticsearch\SearchAdapter\SearchIndexNameResolver $searchIndexNameResolver, $indexerId, \Magento\Framework\App\ScopeResolverInterface $scopeResolver, QueryContainer $queryContainer=null)