Skip to content

Slices #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Solr/Implementor/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ interface ProductRepository
public function getProductsInChunks($storeId, ProductIdChunks $chunks);

/**
* @param null|int $sliceId
* @param null|int $totalNumberSlices
* @return int[]
*/
public function getAllProductIds();
public function getAllProductIds($sliceId = null, $totalNumberSlices = null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that changes in interfaces implemented by other packages are a BC break and require a major version bump. So the next release of solr-base must be 2.0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? You can still use this method as before if you skip the parameters. I'd see that as "new feature", but I don't see the BC break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, now I see... you are right.


/**
* @param null|int[] $productIds
Expand Down
70 changes: 57 additions & 13 deletions src/Solr/Indexer/ProductIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ protected function _getStoreConfig($storeId = null)
* @param array|null $productIds Restrict to given Products if this is set
* @param boolean|string $emptyIndex Whether to truncate the index before refilling it
* @param null|int[] $restrictToStoreIds
* @param null|int $sliceId
* @param null|int $totalNumberSlices
* @throws \Exception
* @throws \IntegerNet\Solr\Exception
*/
public function reindex($productIds = null, $emptyIndex = false, $restrictToStoreIds = null)
public function reindex($productIds = null, $emptyIndex = false, $restrictToStoreIds = null, $sliceId = null, $totalNumberSlices = null)
{
if (is_null($productIds)) {
$this->_getResource()->checkSwapCoresConfiguration($restrictToStoreIds);
if (is_null($productIds) && is_null($sliceId)) {
$this->checkSwapCoresConfiguration($restrictToStoreIds);
}

foreach($this->_config as $storeId => $storeConfig) {
Expand All @@ -114,40 +116,48 @@ public function reindex($productIds = null, $emptyIndex = false, $restrictToStor
$this->storeEmulation->start($storeId);
try {

if (is_null($productIds) && $storeConfig->getIndexingConfig()->isSwapCores()) {
$this->_getResource()->setUseSwapIndex();
if (is_null($productIds) && is_null($sliceId) && $storeConfig->getIndexingConfig()->isSwapCores()) {
$this->activateSwapCore();
}

if (
($emptyIndex && $storeConfig->getIndexingConfig()->isDeleteDocumentsBeforeIndexing())
($emptyIndex && is_null($sliceId) && $storeConfig->getIndexingConfig()->isDeleteDocumentsBeforeIndexing())
|| $emptyIndex === 'force'
) {
$this->_getResource()->deleteAllDocuments($storeId, self::CONTENT_TYPE);
$this->clearIndex($storeId);
}

$pageSize = intval($storeConfig->getIndexingConfig()->getPagesize());
if ($pageSize <= 0) {
$pageSize = 100;
}

$associations = $this->productRepository->getProductAssociations($productIds);
if ($productIds == null) {
$productIdsToIndex = $this->productRepository->getAllProductIds($sliceId, $totalNumberSlices);
} else {
$productIdsToIndex = $productIds;
}

$associations = $this->productRepository->getProductAssociations($productIdsToIndex);
$chunks = ProductIdChunks::withAssociationsTogether(
$productIds == null ? $this->productRepository->getAllProductIds() : $productIds,
$productIdsToIndex,
$associations,
$pageSize);
$productIterator = $this->productRepository->getProductsInChunks($storeId, $chunks);
$this->_indexProductCollection($emptyIndex, $productIterator, $storeId, $productIds, $associations);
$this->_indexProductCollection($emptyIndex, $productIterator, $storeId, $productIdsToIndex, $associations);

$this->_getResource()->setUseSwapIndex(false);
if (is_null($productIds) && is_null($sliceId) && $storeConfig->getIndexingConfig()->isSwapCores()) {
$this->deactivateSwapCore();
}
} catch (\Exception $e) {
$this->storeEmulation->stop();
throw $e;
}
$this->storeEmulation->stop();
}

if (is_null($productIds)) {
$this->_getResource()->swapCores($restrictToStoreIds);
if (is_null($productIds) && is_null($sliceId)) {
$this->swapCores($restrictToStoreIds);
}
}

Expand Down Expand Up @@ -514,5 +524,39 @@ protected function _indexProductCollection($emptyIndex, PagedProductIterator $pr
return $storeId;
}

/**
* @param $storeId
*/
public function clearIndex($storeId)
{
$this->_getResource()->deleteAllDocuments($storeId, self::CONTENT_TYPE);
}

public function activateSwapCore()
{
$this->_getResource()->setUseSwapIndex();
}

public function deactivateSwapCore()
{
$this->_getResource()->setUseSwapIndex(false);
}

/**
* @param null|int[] $restrictToStoreIds
*/
public function swapCores($restrictToStoreIds)
{
$this->_getResource()->swapCores($restrictToStoreIds);
}

/**
* @param $restrictToStoreIds
*/
public function checkSwapCoresConfiguration($restrictToStoreIds)
{
return $this->_getResource()->checkSwapCoresConfiguration($restrictToStoreIds);
}


}