7
7
8
8
use Magento \Elasticsearch \SearchAdapter \QueryAwareInterface ;
9
9
use Magento \Elasticsearch \SearchAdapter \QueryContainer ;
10
+ use Magento \Framework \App \ObjectManager ;
11
+ use Psr \Log \LoggerInterface ;
10
12
11
13
/**
12
14
* Elastic search data provider
@@ -83,6 +85,11 @@ class DataProvider implements \Magento\Framework\Search\Dynamic\DataProviderInte
83
85
*/
84
86
private $ queryContainer ;
85
87
88
+ /**
89
+ * @var LoggerInterface
90
+ */
91
+ private $ logger ;
92
+
86
93
/**
87
94
* @param \Magento\Elasticsearch\SearchAdapter\ConnectionManager $connectionManager
88
95
* @param \Magento\Elasticsearch\Model\Adapter\FieldMapperInterface $fieldMapper
@@ -94,7 +101,7 @@ class DataProvider implements \Magento\Framework\Search\Dynamic\DataProviderInte
94
101
* @param string $indexerId
95
102
* @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
96
103
* @param QueryContainer|null $queryContainer
97
- *
104
+ * @param LoggerInterface|null $logger
98
105
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
99
106
*/
100
107
public function __construct (
@@ -107,7 +114,8 @@ public function __construct(
107
114
\Magento \Elasticsearch \SearchAdapter \SearchIndexNameResolver $ searchIndexNameResolver ,
108
115
$ indexerId ,
109
116
\Magento \Framework \App \ScopeResolverInterface $ scopeResolver ,
110
- QueryContainer $ queryContainer = null
117
+ QueryContainer $ queryContainer = null ,
118
+ LoggerInterface $ logger = null
111
119
) {
112
120
$ this ->connectionManager = $ connectionManager ;
113
121
$ this ->fieldMapper = $ fieldMapper ;
@@ -119,6 +127,7 @@ public function __construct(
119
127
$ this ->indexerId = $ indexerId ;
120
128
$ this ->scopeResolver = $ scopeResolver ;
121
129
$ this ->queryContainer = $ queryContainer ;
130
+ $ this ->logger = $ logger ?? ObjectManager::getInstance ()->get (LoggerInterface::class);
122
131
}
123
132
124
133
/**
@@ -154,16 +163,19 @@ public function getAggregations(\Magento\Framework\Search\Dynamic\EntityStorage
154
163
],
155
164
];
156
165
157
- $ queryResult = $ this ->connectionManager ->getConnection ()
158
- ->query ($ query );
159
-
160
- if (isset ($ queryResult ['aggregations ' ]['prices ' ])) {
161
- $ aggregations = [
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 ' ],
166
- ];
166
+ try {
167
+ $ queryResult = $ this ->connectionManager ->getConnection ()
168
+ ->query ($ query );
169
+ if (isset ($ queryResult ['aggregations ' ]['prices ' ])) {
170
+ $ aggregations = [
171
+ 'count ' => $ queryResult ['aggregations ' ]['prices ' ]['count ' ],
172
+ 'max ' => $ queryResult ['aggregations ' ]['prices ' ]['max ' ],
173
+ 'min ' => $ queryResult ['aggregations ' ]['prices ' ]['min ' ],
174
+ 'std ' => $ queryResult ['aggregations ' ]['prices ' ]['std_deviation ' ],
175
+ ];
176
+ }
177
+ } catch (\Exception $ e ) {
178
+ $ this ->logger ->critical ($ e );
167
179
}
168
180
169
181
return $ aggregations ;
@@ -202,8 +214,6 @@ public function getAggregation(
202
214
$ range ,
203
215
\Magento \Framework \Search \Dynamic \EntityStorage $ entityStorage
204
216
) {
205
- $ result = [];
206
-
207
217
$ query = $ this ->getBasicSearchQuery ($ entityStorage );
208
218
209
219
$ fieldName = $ this ->fieldMapper ->getFieldName ($ bucket ->getField ());
@@ -217,11 +227,16 @@ public function getAggregation(
217
227
],
218
228
];
219
229
220
- $ queryResult = $ this ->connectionManager ->getConnection ()
221
- ->query ($ query );
222
- foreach ($ queryResult ['aggregations ' ]['prices ' ]['buckets ' ] as $ bucket ) {
223
- $ key = (int )($ bucket ['key ' ] / $ range + 1 );
224
- $ result [$ key ] = $ bucket ['doc_count ' ];
230
+ $ result = [];
231
+ try {
232
+ $ queryResult = $ this ->connectionManager ->getConnection ()
233
+ ->query ($ query );
234
+ foreach ($ queryResult ['aggregations ' ]['prices ' ]['buckets ' ] as $ bucket ) {
235
+ $ key = (int )($ bucket ['key ' ] / $ range + 1 );
236
+ $ result [$ key ] = $ bucket ['doc_count ' ];
237
+ }
238
+ } catch (\Exception $ e ) {
239
+ $ this ->logger ->critical ($ e );
225
240
}
226
241
227
242
return $ result ;
0 commit comments