Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Improved.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class Improved implements AlgorithmInterface
15 {
19  private $algorithm;
20 
24  private $dataProvider;
25 
29  private $options;
30 
36  public function __construct(
37  DataProviderInterface $dataProvider,
38  Algorithm $algorithm,
39  OptionsInterface $options
40  ) {
41  $this->algorithm = $algorithm;
42  $this->dataProvider = $dataProvider;
43  $this->options = $options;
44  }
45 
49  public function getItems(
50  BucketInterface $bucket,
51  array $dimensions,
52  \Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
53  ) {
54  $aggregations = $this->dataProvider->getAggregations($entityStorage);
55 
56  $options = $this->options->get();
57  if ($aggregations['count'] < $options['interval_division_limit']) {
58  return [];
59  }
60  $this->algorithm->setStatistics(
61  $aggregations['min'],
62  $aggregations['max'],
63  $aggregations['std'],
64  $aggregations['count']
65  );
66 
67  $this->algorithm->setLimits($aggregations['min'], $aggregations['max'] + 0.01);
68 
69  $interval = $this->dataProvider->getInterval($bucket, $dimensions, $entityStorage);
70  $data = $this->algorithm->calculateSeparators($interval);
71 
72  $data[0]['from'] = ''; // We should not calculate min and max value
73  $data[count($data) - 1]['to'] = '';
74 
75  $dataSize = count($data);
76  for ($key = 0; $key < $dataSize; $key++) {
77  if (isset($data[$key + 1])) {
78  $data[$key]['to'] = $data[$key + 1]['from'];
79  }
80  }
81 
82  return $data;
83  }
84 }
getItems(BucketInterface $bucket, array $dimensions, \Magento\Framework\Search\Dynamic\EntityStorage $entityStorage)
Definition: Improved.php:49
__construct(DataProviderInterface $dataProvider, Algorithm $algorithm, OptionsInterface $options)
Definition: Improved.php:36