Skip to content

Commit 579cf79

Browse files
committed
MAGE-1151: index builders interfaces
1 parent d61d854 commit 579cf79

File tree

8 files changed

+187
-38
lines changed

8 files changed

+187
-38
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Api\IndexBuilder;
4+
5+
interface IndexBuilderInterface
6+
{
7+
public function buildIndex(int $storeId, ?array $ids, ?array $options): void;
8+
9+
public function buildIndexFull(int $storeId, ?array $options): void;
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Api\IndexBuilder;
4+
5+
interface UpdatableIndexBuilderInterface extends IndexBuilderInterface
6+
{
7+
public function buildIndexList(int $storeId, ?array $ids, ?array $options): void;
8+
}

Helper/Data.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public function __construct(
4141
* @throws \Exception
4242
*
4343
* @deprecated
44-
* Use Algolia\AlgoliaSearch\Service\AdditionalSection\IndexBuilder::buildIndex() instead
44+
* Use Algolia\AlgoliaSearch\Service\AdditionalSection\IndexBuilder::buildIndexFull() instead
4545
*/
4646
public function rebuildStoreAdditionalSectionsIndex(int $storeId): void
4747
{
48-
$this->additionalSectionIndexBuilder->buildIndex($storeId);
48+
$this->additionalSectionIndexBuilder->buildIndexFull($storeId);
4949
}
5050

5151
/**
@@ -56,26 +56,27 @@ public function rebuildStoreAdditionalSectionsIndex(int $storeId): void
5656
* @throws NoSuchEntityException
5757
*
5858
* @deprecated
59-
* Use Algolia\AlgoliaSearch\Service\Page\IndexBuilder::buildIndex() instead
59+
* Use Algolia\AlgoliaSearch\Service\Page\IndexBuilder::buildIndexFull() instead
6060
*/
6161
public function rebuildStorePageIndex($storeId, array $pageIds = null): void
6262
{
63-
$this->pageIndexBuilder->buildIndex($storeId, $pageIds);
63+
$this->pageIndexBuilder->buildIndexFull($storeId, ['ids' => $pageIds]);
6464
}
6565

6666
/**
6767
* @param $storeId
68-
* @param $categoryIds
68+
* @param null $categoryIds
6969
* @return void
70+
* @throws AlgoliaException
7071
* @throws LocalizedException
7172
* @throws NoSuchEntityException
7273
*
7374
* @deprecated
74-
* Use Algolia\AlgoliaSearch\Service\Category\IndexBuilder::rebuildEntityIds() instead
75+
* Use Algolia\AlgoliaSearch\Service\Category\IndexBuilder::buildIndexList() instead
7576
*/
7677
public function rebuildStoreCategoryIndex($storeId, $categoryIds = null): void
7778
{
78-
$this->categoryIndexBuilder->rebuildEntityIds($storeId, $categoryIds);
79+
$this->categoryIndexBuilder->buildIndexList($storeId, $categoryIds);
7980
}
8081

8182
/**
@@ -86,11 +87,11 @@ public function rebuildStoreCategoryIndex($storeId, $categoryIds = null): void
8687
* @throws NoSuchEntityException
8788
*
8889
* @deprecated
89-
* Use Algolia\AlgoliaSearch\Service\Suggestion:\IndexBuilder:buildIndex() instead
90+
* Use Algolia\AlgoliaSearch\Service\Suggestion:\IndexBuilder:buildIndexFull() instead
9091
*/
9192
public function rebuildStoreSuggestionIndex(int $storeId): void
9293
{
93-
$this->suggestionIndexBuilder->buildIndex($storeId);
94+
$this->suggestionIndexBuilder->buildIndexFull($storeId);
9495
}
9596

9697
/**
@@ -100,11 +101,11 @@ public function rebuildStoreSuggestionIndex(int $storeId): void
100101
* @throws \Exception
101102
*
102103
* @deprecated
103-
* Use Algolia\AlgoliaSearch\Service\Product\IndexBuilder::rebuildEntityIds() instead
104+
* Use Algolia\AlgoliaSearch\Service\Product\IndexBuilder::buildIndexList() instead
104105
*/
105106
public function rebuildStoreProductIndex(int $storeId, array $productIds): void
106107
{
107-
$this->productIndexBuilder->rebuildEntityIds($storeId, $productIds);
108+
$this->productIndexBuilder->buildIndexList($storeId, $productIds);
108109
}
109110

110111
/**
@@ -117,11 +118,19 @@ public function rebuildStoreProductIndex(int $storeId, array $productIds): void
117118
* @throws \Exception
118119
*
119120
* @deprecated
120-
* Use Algolia\AlgoliaSearch\Service\Product\IndexBuilder::buildIndex() instead
121+
* Use Algolia\AlgoliaSearch\Service\Product\IndexBuilder::buildIndexFull() instead
121122
*/
122123
public function rebuildProductIndex(int $storeId, ?array $productIds, int $page, int $pageSize, bool $useTmpIndex): void
123124
{
124-
$this->productIndexBuilder->buildIndex($storeId, $productIds, $page, $pageSize, $useTmpIndex);
125+
$this->productIndexBuilder->buildIndexFull(
126+
$storeId,
127+
[
128+
'productIds' => $productIds,
129+
'page' => $page,
130+
'pageSize' => $pageSize,
131+
'useTmpIndex' => $useTmpIndex
132+
]
133+
);
125134
}
126135

127136
/**
@@ -134,11 +143,11 @@ public function rebuildProductIndex(int $storeId, ?array $productIds, int $page,
134143
* @throws \Exception
135144
*
136145
* @deprecated
137-
* Use Algolia\AlgoliaSearch\Service\Category\IndexBuilder::buildIndex() instead
146+
* Use Algolia\AlgoliaSearch\Service\Category\IndexBuilder::buildIndexFull() instead
138147
*/
139148
public function rebuildCategoryIndex(int $storeId, int $page, int $pageSize): void
140149
{
141-
$this->categoryIndexBuilder->buildIndex($storeId, $page, $pageSize);
150+
$this->categoryIndexBuilder->buildIndexFull($storeId, ['page' => $page, 'pageSize' => $pageSize]);
142151
}
143152

144153
/**

Service/AdditionalSection/IndexBuilder.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Service\AdditionalSection;
44

5+
use Algolia\AlgoliaSearch\Api\IndexBuilder\IndexBuilderInterface;
56
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
67
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
78
use Algolia\AlgoliaSearch\Helper\AlgoliaHelper;
@@ -14,7 +15,7 @@
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516
use Magento\Store\Model\App\Emulation;
1617

17-
class IndexBuilder extends AbstractIndexBuilder
18+
class IndexBuilder extends AbstractIndexBuilder implements IndexBuilderInterface
1819
{
1920
public function __construct(
2021
protected ConfigHelper $configHelper,
@@ -29,13 +30,27 @@ public function __construct(
2930

3031
/**
3132
* @param int $storeId
33+
* @param array|null $options
3234
* @return void
3335
* @throws AlgoliaException
3436
* @throws ExceededRetriesException
3537
* @throws NoSuchEntityException
36-
* @throws \Exception
3738
*/
38-
public function buildIndex(int $storeId): void
39+
public function buildIndexFull(int $storeId, array $options = null): void
40+
{
41+
$this->buildIndex($storeId, null, null);
42+
}
43+
44+
/**
45+
* @param int $storeId
46+
* @param array|null $ids
47+
* @param array|null $options
48+
* @return void
49+
* @throws AlgoliaException
50+
* @throws ExceededRetriesException
51+
* @throws NoSuchEntityException
52+
*/
53+
public function buildIndex(int $storeId, ?array $ids, ?array $options): void
3954
{
4055
if ($this->isIndexingEnabled($storeId) === false) {
4156
return;

Service/Category/IndexBuilder.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Service\Category;
44

5+
use Algolia\AlgoliaSearch\Api\IndexBuilder\UpdatableIndexBuilderInterface;
56
use Algolia\AlgoliaSearch\Exception\CategoryReindexingException;
67
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
78
use Algolia\AlgoliaSearch\Helper\AlgoliaHelper;
@@ -15,7 +16,7 @@
1516
use Magento\Framework\Exception\NoSuchEntityException;
1617
use Magento\Store\Model\App\Emulation;
1718

18-
class IndexBuilder extends AbstractIndexBuilder
19+
class IndexBuilder extends AbstractIndexBuilder implements UpdatableIndexBuilderInterface
1920
{
2021
public function __construct(
2122
protected ConfigHelper $configHelper,
@@ -30,22 +31,55 @@ public function __construct(
3031

3132
/**
3233
* @param int $storeId
33-
* @param int $page
34-
* @param int $pageSize
34+
* @param array|null $options
3535
* @return void
3636
* @throws LocalizedException
3737
* @throws NoSuchEntityException
38+
* @throws AlgoliaException
39+
*/
40+
public function buildIndexFull(int $storeId, array $options = null): void
41+
{
42+
$this->buildIndex($storeId, null, $options);
43+
}
44+
45+
/**
46+
* @param int $storeId
47+
* @param array|null $ids
48+
* @param array|null $options
49+
* @return void
50+
* @throws AlgoliaException
51+
* @throws LocalizedException
52+
* @throws NoSuchEntityException
53+
*/
54+
public function buildIndexList(int $storeId, array $ids = null, array $options = null): void
55+
{
56+
$this->buildIndex($storeId, $ids, $options);
57+
}
58+
59+
/**
60+
* @param int $storeId
61+
* @param array|null $ids
62+
* @param array|null $options
63+
* @return void
64+
* @throws AlgoliaException
65+
* @throws LocalizedException
66+
* @throws NoSuchEntityException
3867
* @throws \Exception
3968
*/
40-
public function buildIndex(int $storeId, int $page, int $pageSize): void
69+
public function buildIndex(int $storeId, ?array $ids, ?array $options): void
4170
{
4271
if ($this->isIndexingEnabled($storeId) === false) {
4372
return;
4473
}
4574

75+
if (!is_null($ids)) {
76+
$this->rebuildEntityIds($storeId, $ids);
77+
return;
78+
}
79+
4680
$this->startEmulation($storeId);
4781
$collection = $this->categoryHelper->getCategoryCollectionQuery($storeId, null);
48-
$this->buildIndexPage($storeId, $collection, $page, $pageSize);
82+
$this->buildIndexPage($storeId, $collection, $options['page'], $options['pageSize']);
4983
$this->stopEmulation();
5084
}
5185

Service/Page/IndexBuilder.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Algolia\AlgoliaSearch\Service\Page;
44

5+
use Algolia\AlgoliaSearch\Api\IndexBuilder\IndexBuilderInterface;
56
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
7+
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
68
use Algolia\AlgoliaSearch\Helper\AlgoliaHelper;
79
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
810
use Algolia\AlgoliaSearch\Helper\Entity\PageHelper;
@@ -13,7 +15,7 @@
1315
use Magento\Framework\Exception\NoSuchEntityException;
1416
use Magento\Store\Model\App\Emulation;
1517

16-
class IndexBuilder extends AbstractIndexBuilder
18+
class IndexBuilder extends AbstractIndexBuilder implements IndexBuilderInterface
1719
{
1820
public function __construct(
1921
protected ConfigHelper $configHelper,
@@ -26,14 +28,29 @@ public function __construct(
2628
parent::__construct($configHelper, $logger, $emulation, $scopeCodeResolver, $algoliaHelper);
2729
}
2830

31+
/**
32+
* @param int $storeId
33+
* @param array|null $options
34+
* @return void
35+
* @throws AlgoliaException
36+
* @throws ExceededRetriesException
37+
* @throws NoSuchEntityException
38+
*/
39+
public function buildIndexFull(int $storeId, array $options = null): void
40+
{
41+
$this->buildIndex($storeId, isset($options['ids'])?: null, null);
42+
}
43+
2944
/**
3045
* @param $storeId
31-
* @param array|null $pageIds
46+
* @param array|null $ids
47+
* @param array|null $options
3248
* @return void
3349
* @throws AlgoliaException
50+
* @throws ExceededRetriesException
3451
* @throws NoSuchEntityException
3552
*/
36-
public function buildIndex($storeId, array $pageIds = null): void
53+
public function buildIndex($storeId, ?array $ids, ?array $options): void
3754
{
3855
if ($this->isIndexingEnabled($storeId) === false) {
3956
return;
@@ -50,12 +67,12 @@ public function buildIndex($storeId, array $pageIds = null): void
5067

5168
$this->startEmulation($storeId);
5269

53-
$pages = $this->pageHelper->getPages($storeId, $pageIds);
70+
$pages = $this->pageHelper->getPages($storeId, $ids);
5471

5572
$this->stopEmulation();
5673

5774
// if there are pageIds defined, do not index to _tmp
58-
$isFullReindex = (!$pageIds);
75+
$isFullReindex = (!$ids);
5976

6077
if (isset($pages['toIndex']) && count($pages['toIndex'])) {
6178
$pagesToIndex = $pages['toIndex'];

0 commit comments

Comments
 (0)