Skip to content

Commit 0c417ea

Browse files
committed
MAGE-1260: introduced entity index options builders
1 parent 46d1adc commit 0c417ea

File tree

6 files changed

+124
-31
lines changed

6 files changed

+124
-31
lines changed

Helper/Entity/ProductHelper.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,22 @@ public function getIndexSettings(?int $storeId = null): array
301301
}
302302

303303
/**
304-
* @param string $indexName
305-
* @param string $indexNameTmp
304+
* @param IndexOptionsInterface $indexOptions
305+
* @param IndexOptionsInterface $indexTmpOptions
306306
* @param int $storeId
307307
* @param bool $saveToTmpIndicesToo
308308
* @return void
309309
* @throws AlgoliaException
310310
* @throws LocalizedException
311311
* @throws NoSuchEntityException
312312
*/
313-
public function setSettings(string $indexName, string $indexNameTmp, int $storeId, bool $saveToTmpIndicesToo = false): void
314-
{
313+
public function setSettings(
314+
IndexOptionsInterface $indexOptions,
315+
IndexOptionsInterface $indexTmpOptions,
316+
int $storeId,
317+
bool $saveToTmpIndicesToo = false
318+
): void {
315319
$indexSettings = $this->getIndexSettings($storeId);
316-
$indexOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexName, $storeId);
317-
$indexTmpOptions = $this->indexOptionsBuilder->buildWithEnforcedIndex($indexNameTmp, $storeId);
318320

319321
$this->algoliaConnector->setSettings(
320322
$indexOptions,
@@ -331,7 +333,7 @@ public function setSettings(string $indexName, string $indexNameTmp, int $storeI
331333
$indexSettings,
332334
false,
333335
true,
334-
$indexName
336+
$indexOptions->getIndexName()
335337
);
336338

337339
$this->logger->log('Pushing the same settings to TMP index as well');

Model/IndicesConfigurator.php

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,30 @@
1414
use Algolia\AlgoliaSearch\Service\AlgoliaConnector;
1515
use Algolia\AlgoliaSearch\Service\AlgoliaCredentialsManager;
1616
use Algolia\AlgoliaSearch\Service\IndexOptionsBuilder;
17+
use Algolia\AlgoliaSearch\Service\Category\IndexOptionsBuilder as CategoryIndexOptionsBuilder;
18+
use Algolia\AlgoliaSearch\Service\Page\IndexOptionsBuilder as PageIndexOptionsBuilder;
19+
use Algolia\AlgoliaSearch\Service\Product\IndexOptionsBuilder as ProductIndexOptionsBuilder;
20+
use Algolia\AlgoliaSearch\Service\Suggestion\IndexOptionsBuilder as SuggestionIndexOptionsBuilder;
1721
use Magento\Framework\Exception\NoSuchEntityException;
1822

1923
class IndicesConfigurator
2024
{
2125
public function __construct(
22-
protected Data $baseHelper,
23-
protected IndexOptionsBuilder $indexOptionsBuilder,
24-
protected AlgoliaConnector $algoliaConnector,
25-
protected ConfigHelper $configHelper,
26-
protected ProductHelper $productHelper,
27-
protected CategoryHelper $categoryHelper,
28-
protected PageHelper $pageHelper,
29-
protected SuggestionHelper $suggestionHelper,
30-
protected AdditionalSectionHelper $additionalSectionHelper,
31-
protected AlgoliaCredentialsManager $algoliaCredentialsManager,
32-
protected DiagnosticsLogger $logger
26+
protected Data $baseHelper,
27+
protected IndexOptionsBuilder $indexOptionsBuilder,
28+
protected CategoryIndexOptionsBuilder $categoryIndexOptionsBuilder,
29+
protected PageIndexOptionsBuilder $pageIndexOptionsBuilder,
30+
protected ProductIndexOptionsBuilder $productIndexOptionsBuilder,
31+
protected SuggestionIndexOptionsBuilder $suggestionIndexOptionsBuilder,
32+
protected AlgoliaConnector $algoliaConnector,
33+
protected ConfigHelper $configHelper,
34+
protected ProductHelper $productHelper,
35+
protected CategoryHelper $categoryHelper,
36+
protected PageHelper $pageHelper,
37+
protected SuggestionHelper $suggestionHelper,
38+
protected AdditionalSectionHelper $additionalSectionHelper,
39+
protected AlgoliaCredentialsManager $algoliaCredentialsManager,
40+
protected DiagnosticsLogger $logger
3341
) {}
3442

3543
/**
@@ -98,11 +106,7 @@ protected function setCategoriesSettings(int $storeId): void
98106
$this->logger->start($logEventName, true);
99107

100108
$settings = $this->categoryHelper->getIndexSettings($storeId);
101-
102-
$indexOptions = $this->indexOptionsBuilder->buildWithComputedIndex(
103-
CategoryHelper::INDEX_NAME_SUFFIX,
104-
$storeId
105-
);
109+
$indexOptions = $this->categoryIndexOptionsBuilder->buildEntityIndexOptions($storeId);
106110

107111
$this->algoliaConnector->setSettings(
108112
$indexOptions,
@@ -127,8 +131,7 @@ protected function setPagesSettings(int $storeId): void
127131
$this->logger->start($logEventName, true);
128132

129133
$settings = $this->pageHelper->getIndexSettings($storeId);
130-
131-
$indexOptions = $this->indexOptionsBuilder->buildWithComputedIndex(PageHelper::INDEX_NAME_SUFFIX, $storeId);
134+
$indexOptions = $this->pageIndexOptionsBuilder->buildEntityIndexOptions($storeId);
132135

133136
$this->algoliaConnector->setSettings(
134137
$indexOptions,
@@ -153,7 +156,7 @@ protected function setQuerySuggestionsSettings(int $storeId): void
153156
$this->logger->start($logEventName, true);
154157

155158
$settings = $this->suggestionHelper->getIndexSettings($storeId);
156-
$indexOptions = $this->indexOptionsBuilder->buildWithComputedIndex(SuggestionHelper::INDEX_NAME_SUFFIX, $storeId);
159+
$indexOptions = $this->suggestionIndexOptionsBuilder->buildEntityIndexOptions($storeId);
157160

158161
$this->algoliaConnector->setSettings(
159162
$indexOptions,
@@ -212,13 +215,13 @@ protected function setProductsSettings(int $storeId, bool $useTmpIndex): void
212215
$logEventName = 'Pushing settings for products indices.';
213216
$this->logger->start($logEventName, true);
214217

215-
$indexName = $this->productHelper->getIndexName($storeId);
216-
$indexNameTmp = $this->productHelper->getTempIndexName($storeId);
218+
$indexOptions = $this->productIndexOptionsBuilder->buildEntityIndexOptions($storeId);
219+
$indexTmpOptions = $this->productIndexOptionsBuilder->buildEntityIndexOptions($storeId, true);
217220

218-
$this->logger->log('Index name: ' . $indexName);
219-
$this->logger->log('TMP Index name: ' . $indexNameTmp);
221+
$this->logger->log('Index name: ' . $indexOptions->getIndexName());
222+
$this->logger->log('TMP Index name: ' . $indexTmpOptions->getIndexName());
220223

221-
$this->productHelper->setSettings($indexName, $indexNameTmp, $storeId, $useTmpIndex);
224+
$this->productHelper->setSettings($indexOptions, $indexTmpOptions, $storeId, $useTmpIndex);
222225

223226
$this->logger->stop($logEventName, true);
224227
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Service\AdditionalSection;
4+
5+
use Algolia\AlgoliaSearch\Api\Builder\EntityIndexOptionsBuilderInterface;
6+
use Algolia\AlgoliaSearch\Api\Data\IndexOptionsInterface;
7+
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
8+
use Algolia\AlgoliaSearch\Helper\Entity\AdditionalSectionHelper;
9+
use Algolia\AlgoliaSearch\Service\IndexOptionsBuilder as BaseIndexOptionsBuilder;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
class IndexOptionsBuilder extends BaseIndexOptionsBuilder implements EntityIndexOptionsBuilderInterface
13+
{
14+
/**
15+
* @throws NoSuchEntityException
16+
* @throws AlgoliaException
17+
*/
18+
public function buildEntityIndexOptions(int $storeId, ?bool $isTmp = false): IndexOptionsInterface
19+
{
20+
return $this->buildWithComputedIndex(AdditionalSectionHelper::INDEX_NAME_SUFFIX, $storeId, $isTmp);
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Service\Category;
4+
5+
use Algolia\AlgoliaSearch\Api\Builder\EntityIndexOptionsBuilderInterface;
6+
use Algolia\AlgoliaSearch\Api\Data\IndexOptionsInterface;
7+
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
8+
use Algolia\AlgoliaSearch\Helper\Entity\CategoryHelper;
9+
use Algolia\AlgoliaSearch\Service\IndexOptionsBuilder as BaseIndexOptionsBuilder;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
class IndexOptionsBuilder extends BaseIndexOptionsBuilder implements EntityIndexOptionsBuilderInterface
13+
{
14+
/**
15+
* @throws NoSuchEntityException
16+
* @throws AlgoliaException
17+
*/
18+
public function buildEntityIndexOptions(int $storeId, ?bool $isTmp = false): IndexOptionsInterface
19+
{
20+
return $this->buildWithComputedIndex(CategoryHelper::INDEX_NAME_SUFFIX, $storeId, $isTmp);
21+
}
22+
}

Service/Page/IndexOptionsBuilder.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Service\Page;
4+
5+
use Algolia\AlgoliaSearch\Api\Builder\EntityIndexOptionsBuilderInterface;
6+
use Algolia\AlgoliaSearch\Api\Data\IndexOptionsInterface;
7+
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
8+
use Algolia\AlgoliaSearch\Helper\Entity\PageHelper;
9+
use Algolia\AlgoliaSearch\Service\IndexOptionsBuilder as BaseIndexOptionsBuilder;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
class IndexOptionsBuilder extends BaseIndexOptionsBuilder implements EntityIndexOptionsBuilderInterface
13+
{
14+
/**
15+
* @throws NoSuchEntityException
16+
* @throws AlgoliaException
17+
*/
18+
public function buildEntityIndexOptions(int $storeId, ?bool $isTmp = false): IndexOptionsInterface
19+
{
20+
return $this->buildWithComputedIndex(PageHelper::INDEX_NAME_SUFFIX, $storeId, $isTmp);
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Service\Suggestion;
4+
5+
use Algolia\AlgoliaSearch\Api\Builder\EntityIndexOptionsBuilderInterface;
6+
use Algolia\AlgoliaSearch\Api\Data\IndexOptionsInterface;
7+
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
8+
use Algolia\AlgoliaSearch\Helper\Entity\SuggestionHelper;
9+
use Algolia\AlgoliaSearch\Service\IndexOptionsBuilder as BaseIndexOptionsBuilder;
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
12+
class IndexOptionsBuilder extends BaseIndexOptionsBuilder implements EntityIndexOptionsBuilderInterface
13+
{
14+
/**
15+
* @throws NoSuchEntityException
16+
* @throws AlgoliaException
17+
*/
18+
public function buildEntityIndexOptions(int $storeId, ?bool $isTmp = false): IndexOptionsInterface
19+
{
20+
return $this->buildWithComputedIndex(SuggestionHelper::INDEX_NAME_SUFFIX, $storeId, $isTmp);
21+
}
22+
}

0 commit comments

Comments
 (0)