Skip to content

Commit

Permalink
fix: some polish for indexing task, only re-indexing of a specific su…
Browse files Browse the repository at this point in the history
…bclass of a index
  • Loading branch information
wilr committed Aug 30, 2024
1 parent 2658ce0 commit a3c286a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Tasks/AlgoliaReindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,34 @@ public function run($request)

// find all classes we have to index and do so
foreach ($algoliaService->indexes as $indexName => $index) {
echo 'Updating index ' . $indexName . PHP_EOL;
$environmentizedIndexName = $algoliaService->environmentizeIndex($indexName);

echo 'Updating index ' . $environmentizedIndexName . PHP_EOL;

$classes = (isset($index['includeClasses'])) ? $index['includeClasses'] : null;
$indexFilters = (isset($index['includeFilter'])) ? $index['includeFilter'] : [];

if ($classes) {
foreach ($classes as $candidate) {
if ($targetClass && $targetClass !== $candidate) {
continue;
// check to see if target class is a subclass of the candidate
if (!is_subclass_of($targetClass, $candidate)) {
continue;
} else {
$candidate = $targetClass;
}
}


$items = $this->getItems($candidate, $filter, $indexFilters);

$filterLabel = implode(',', array_filter(array_merge([$filter], [$indexFilters[$candidate] ?? ''])));

echo sprintf(
'| Found %s %s remaining to index which match filter (%s)%s',
'| Found %s %s remaining to index %s%s',
$items->count(),
$candidate,
implode(',', array_merge([$filter], [$indexFilters[$candidate] ?? ''])),
$filterLabel ? 'which match filters ' . $filterLabel : '',
PHP_EOL
);

Expand All @@ -106,7 +116,7 @@ public function run($request)
}


echo 'Done';
echo 'Done' . PHP_EOL;
}


Expand Down

0 comments on commit a3c286a

Please sign in to comment.