@@ -93,13 +93,15 @@ protected function _getStoreConfig($storeId = null)
93
93
* @param array|null $productIds Restrict to given Products if this is set
94
94
* @param boolean|string $emptyIndex Whether to truncate the index before refilling it
95
95
* @param null|int[] $restrictToStoreIds
96
+ * @param null|int $sliceId
97
+ * @param null|int $totalNumberSlices
96
98
* @throws \Exception
97
99
* @throws \IntegerNet\Solr\Exception
98
100
*/
99
- public function reindex ($ productIds = null , $ emptyIndex = false , $ restrictToStoreIds = null )
101
+ public function reindex ($ productIds = null , $ emptyIndex = false , $ restrictToStoreIds = null , $ sliceId = null , $ totalNumberSlices = null )
100
102
{
101
- if (is_null ($ productIds )) {
102
- $ this ->_getResource ()-> checkSwapCoresConfiguration ($ restrictToStoreIds );
103
+ if (is_null ($ productIds ) && is_null ( $ sliceId ) ) {
104
+ $ this ->checkSwapCoresConfiguration ($ restrictToStoreIds );
103
105
}
104
106
105
107
foreach ($ this ->_config as $ storeId => $ storeConfig ) {
@@ -114,40 +116,48 @@ public function reindex($productIds = null, $emptyIndex = false, $restrictToStor
114
116
$ this ->storeEmulation ->start ($ storeId );
115
117
try {
116
118
117
- if (is_null ($ productIds ) && $ storeConfig ->getIndexingConfig ()->isSwapCores ()) {
118
- $ this ->_getResource ()-> setUseSwapIndex ();
119
+ if (is_null ($ productIds ) && is_null ( $ sliceId ) && $ storeConfig ->getIndexingConfig ()->isSwapCores ()) {
120
+ $ this ->activateSwapCore ();
119
121
}
120
122
121
123
if (
122
- ($ emptyIndex && $ storeConfig ->getIndexingConfig ()->isDeleteDocumentsBeforeIndexing ())
124
+ ($ emptyIndex && is_null ( $ sliceId ) && $ storeConfig ->getIndexingConfig ()->isDeleteDocumentsBeforeIndexing ())
123
125
|| $ emptyIndex === 'force '
124
126
) {
125
- $ this ->_getResource ()-> deleteAllDocuments ( $ storeId, self :: CONTENT_TYPE );
127
+ $ this ->clearIndex ( $ storeId );
126
128
}
127
129
128
130
$ pageSize = intval ($ storeConfig ->getIndexingConfig ()->getPagesize ());
129
131
if ($ pageSize <= 0 ) {
130
132
$ pageSize = 100 ;
131
133
}
132
134
133
- $ associations = $ this ->productRepository ->getProductAssociations ($ productIds );
135
+ if ($ productIds == null ) {
136
+ $ productIdsToIndex = $ this ->productRepository ->getAllProductIds ($ sliceId , $ totalNumberSlices );
137
+ } else {
138
+ $ productIdsToIndex = $ productIds ;
139
+ }
140
+
141
+ $ associations = $ this ->productRepository ->getProductAssociations ($ productIdsToIndex );
134
142
$ chunks = ProductIdChunks::withAssociationsTogether (
135
- $ productIds == null ? $ this -> productRepository -> getAllProductIds () : $ productIds ,
143
+ $ productIdsToIndex ,
136
144
$ associations ,
137
145
$ pageSize );
138
146
$ productIterator = $ this ->productRepository ->getProductsInChunks ($ storeId , $ chunks );
139
- $ this ->_indexProductCollection ($ emptyIndex , $ productIterator , $ storeId , $ productIds , $ associations );
147
+ $ this ->_indexProductCollection ($ emptyIndex , $ productIterator , $ storeId , $ productIdsToIndex , $ associations );
140
148
141
- $ this ->_getResource ()->setUseSwapIndex (false );
149
+ if (is_null ($ productIds ) && is_null ($ sliceId ) && $ storeConfig ->getIndexingConfig ()->isSwapCores ()) {
150
+ $ this ->deactivateSwapCore ();
151
+ }
142
152
} catch (\Exception $ e ) {
143
153
$ this ->storeEmulation ->stop ();
144
154
throw $ e ;
145
155
}
146
156
$ this ->storeEmulation ->stop ();
147
157
}
148
158
149
- if (is_null ($ productIds )) {
150
- $ this ->_getResource ()-> swapCores ($ restrictToStoreIds );
159
+ if (is_null ($ productIds ) && is_null ( $ sliceId ) ) {
160
+ $ this ->swapCores ($ restrictToStoreIds );
151
161
}
152
162
}
153
163
@@ -514,5 +524,39 @@ protected function _indexProductCollection($emptyIndex, PagedProductIterator $pr
514
524
return $ storeId ;
515
525
}
516
526
527
+ /**
528
+ * @param $storeId
529
+ */
530
+ public function clearIndex ($ storeId )
531
+ {
532
+ $ this ->_getResource ()->deleteAllDocuments ($ storeId , self ::CONTENT_TYPE );
533
+ }
534
+
535
+ public function activateSwapCore ()
536
+ {
537
+ $ this ->_getResource ()->setUseSwapIndex ();
538
+ }
539
+
540
+ public function deactivateSwapCore ()
541
+ {
542
+ $ this ->_getResource ()->setUseSwapIndex (false );
543
+ }
544
+
545
+ /**
546
+ * @param null|int[] $restrictToStoreIds
547
+ */
548
+ public function swapCores ($ restrictToStoreIds )
549
+ {
550
+ $ this ->_getResource ()->swapCores ($ restrictToStoreIds );
551
+ }
552
+
553
+ /**
554
+ * @param $restrictToStoreIds
555
+ */
556
+ public function checkSwapCoresConfiguration ($ restrictToStoreIds )
557
+ {
558
+ return $ this ->_getResource ()->checkSwapCoresConfiguration ($ restrictToStoreIds );
559
+ }
560
+
517
561
518
562
}
0 commit comments