55 private $searchIndexNameResolver;
78 $this->fieldName = $fieldName;
79 $this->storeId = $storeId;
80 $this->entityIds = $entityIds;
81 $this->searchIndexNameResolver = $searchIndexNameResolver;
87 public function load($limit, $offset =
null, $lower =
null, $upper =
null)
99 'type' => $this->clientConfig->getEntityType(),
115 '_id' => $this->entityIds,
120 $this->fieldName => array_merge($from, $to),
135 $requestQuery[
'body'][
'from'] = $offset;
137 $queryResult = $this->connectionManager->getConnection()
138 ->query($requestQuery);
140 return $this->arrayValuesToFloat($queryResult[
'hits'][
'hits'], $this->fieldName);
157 'type' => $this->clientConfig->getEntityType(),
158 'search_type' =>
'count',
173 '_id' => $this->entityIds,
178 $this->fieldName => array_merge($from, $to),
191 $queryResult = $this->connectionManager->getConnection()
192 ->query($requestQuery);
194 $offset = $queryResult[
'hits'][
'total'];
199 return $this->
load(
$index - $offset + 1, $offset - 1, $lower);
210 $requestCountQuery = [
212 'type' => $this->clientConfig->getEntityType(),
213 'search_type' =>
'count',
228 '_id' => $this->entityIds,
233 $this->fieldName => array_merge($from, $to),
246 $queryCountResult = $this->connectionManager->getConnection()
247 ->query($requestCountQuery);
249 $offset = $queryCountResult[
'hits'][
'total'];
255 if ($upper !==
null) {
259 $requestQuery = $requestCountQuery;
260 $requestCountQuery[
'body'][
'query'][
'filtered'][
'filter'][
'bool'][
'must'][
'range'] =
261 [$this->fieldName => array_merge($from, $to)];
263 $requestCountQuery[
'body'][
'from'] = $offset - 1;
264 $requestCountQuery[
'body'][
'size'] = $rightIndex - $offset + 1;
266 $queryResult = $this->connectionManager->getConnection()
267 ->query($requestQuery);
269 return array_reverse($this->arrayValuesToFloat($queryResult[
'hits'][
'hits'], $this->fieldName));
278 private function arrayValuesToFloat($hits, $fieldName)
281 foreach ($hits as $hit) {
282 $returnPrices[] = (float) $hit[
'fields'][$fieldName][0];
285 return $returnPrices;
loadNext($data, $rightIndex, $upper=null)
load($limit, $offset=null, $lower=null, $upper=null)
loadPrevious($data, $index, $lower=null)
__construct(ConnectionManager $connectionManager, FieldMapperInterface $fieldMapper, Config $clientConfig, SearchIndexNameResolver $searchIndexNameResolver, $fieldName, $storeId, $entityIds)