diff --git a/README.md b/README.md index 540a4e6..58073c9 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,19 @@ import but only need the active ones you can trigger the task as follows: If you do not have access to a CLI (i.e Silverstripe Cloud) then you can also bulk reindex via a queued job `AlgoliaReindexAllJob`. +### Optional + +`forceAll` forces every Silverstripe record to be re-synced. + +``` +./vendor/bin/sake dev/tasks/AlgoliaReindex "flush=1&forceAll=1" +``` + +`clearAll` truncates the search index before reindexing. + +``` +./vendor/bin/sake dev/tasks/AlgoliaReindex "flush=1&clearAll=1&forceAll=1" +``` ### Customising the indexed attributes (fields) diff --git a/src/Tasks/AlgoliaReindex.php b/src/Tasks/AlgoliaReindex.php index 8ba0efb..9ba995c 100644 --- a/src/Tasks/AlgoliaReindex.php +++ b/src/Tasks/AlgoliaReindex.php @@ -64,6 +64,17 @@ public function run($request) $filter = 'AlgoliaIndexed IS NULL'; } + /** @var AlgoliaService */ + $algoliaService = Injector::inst()->create(AlgoliaService::class); + + if ($request->getVar('clearAll')) { + $indexes = $algoliaService->initIndexes(); + + foreach ($indexes as $indexName => $index) { + $index->clearObjects(); + } + } + if ($targetClass) { $items = $this->getItems($targetClass, $filter); @@ -78,7 +89,6 @@ public function run($request) ); } } else { - $algoliaService = Injector::inst()->create(AlgoliaService::class); // find all classes we have to index and do so foreach ($algoliaService->indexes as $index) {