diff --git a/docs/en/customising_add_search_service.md b/docs/en/customising_add_search_service.md index 319f28e..ec36a5c 100644 --- a/docs/en/customising_add_search_service.md +++ b/docs/en/customising_add_search_service.md @@ -54,7 +54,7 @@ public function addDocument(DocumentInterface $document): ?string foreach (array_keys($indexes) as $indexName) { // your custom API call here $mySearchClient->addDocuementToIndex( - static::environmentizeIndex($indexName), + $this->environmentizeIndex($indexName), $fields ); } @@ -96,7 +96,7 @@ public function removeDocument(DocumentInterface $document): ?string foreach (array_keys($indexes) as $indexName) { // your custom API call here $myAPI->removeDocumentFromIndex( - static::environmentizeIndex($indexName), + $this->environmentizeIndex($indexName), $document->getIdentifier() ); } @@ -132,7 +132,7 @@ public function getDocument(string $id): ?array foreach (array_keys(IndexConfiguration::singleton()->getIndexes()) as $indexName) { // Your API call here $result = $myAPI->retrieveDocumentFromIndex( - static::environmentizeIndex($indexName), + $this->environmentizeIndex($indexName), $id ); @@ -169,7 +169,7 @@ return type should be an array of `DocumentInterface`. public function listDocuments(string $indexName, ?int $pageSize = null, int $currentPage = 0): array { // Your API call here - $request = new ListDocuments(static::environmentizeIndex($indexName)); + $request = new ListDocuments($this->environmentizeIndex($indexName)); $request->setPageSize($pageSize); $request->setCurrentPage($currentPage); @@ -193,7 +193,7 @@ public function getDocumentTotal(string $indexName): int { // Your API call here $response = $myAPI->listDocuments( - static::environmentizeIndex($indexName) + $this->environmentizeIndex($indexName) ); return $response['metadata']['total']; @@ -217,7 +217,7 @@ Return value should be an array describing the current Schema for each index. public function configure(): array { foreach ($indexesToCreate as $index) { - $myAPI->createIndex(static::environmentizeIndex($index)); + $myAPI->createIndex($this->environmentizeIndex($index)); } } ``` diff --git a/src/Admin/IndexedDocumentsResult.php b/src/Admin/IndexedDocumentsResult.php index c3c6189..4372eb0 100644 --- a/src/Admin/IndexedDocumentsResult.php +++ b/src/Admin/IndexedDocumentsResult.php @@ -7,6 +7,12 @@ class IndexedDocumentsResult extends ViewableData { + public string $IndexName; + + public int $DBDocs; + + public int $RemoteDocs; + public function summaryFields(): array { return [ diff --git a/src/Admin/SearchAdmin.php b/src/Admin/SearchAdmin.php index 962ec34..cd67677 100644 --- a/src/Admin/SearchAdmin.php +++ b/src/Admin/SearchAdmin.php @@ -24,7 +24,6 @@ use SilverStripe\SearchService\Jobs\ReindexJob; use SilverStripe\SearchService\Jobs\RemoveDataObjectJob; use SilverStripe\SearchService\Tasks\SearchReindex; -use SilverStripe\SearchServiceElastic\Service\EnterpriseSearchService; use SilverStripe\Security\Permission; use SilverStripe\Security\PermissionProvider; use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; @@ -208,7 +207,7 @@ private function buildIndexedDocumentsList(): ArrayList } $result = new IndexedDocumentsResult(); - $result->IndexName = EnterpriseSearchService::environmentizeIndex($index); + $result->IndexName = $indexer->environmentizeIndex($index); $result->DBDocs = $localCount; $result->RemoteDocs = $indexer->getDocumentTotal($index); $list->push($result); diff --git a/src/Interfaces/IndexingInterface.php b/src/Interfaces/IndexingInterface.php index 403792e..4589472 100644 --- a/src/Interfaces/IndexingInterface.php +++ b/src/Interfaces/IndexingInterface.php @@ -8,6 +8,11 @@ interface IndexingInterface extends BatchDocumentInterface { + /** + * Often used for resu + */ + public function environmentizeIndex(string $indexName): string; + /** * @return string|null ID of the Document added * @throws IndexingServiceException diff --git a/src/Service/Naive/NaiveSearchService.php b/src/Service/Naive/NaiveSearchService.php index 0a74507..01dee9e 100644 --- a/src/Service/Naive/NaiveSearchService.php +++ b/src/Service/Naive/NaiveSearchService.php @@ -5,10 +5,22 @@ use SilverStripe\SearchService\Interfaces\BatchDocumentRemovalInterface; use SilverStripe\SearchService\Interfaces\DocumentInterface; use SilverStripe\SearchService\Interfaces\IndexingInterface; +use SilverStripe\SearchService\Service\IndexConfiguration; class NaiveSearchService implements IndexingInterface, BatchDocumentRemovalInterface { + public function environmentizeIndex(string $indexName): string + { + $variant = IndexConfiguration::singleton()->getIndexVariant(); + + if ($variant) { + return sprintf('%s-%s', $variant, $indexName); + } + + return $indexName; + } + public function addDocument(DocumentInterface $document): ?string { return null;