Skip to content

Commit 43c8c3e

Browse files
committed
Working through Fluent support changes
1 parent ff91842 commit 43c8c3e

4 files changed

Lines changed: 34 additions & 30 deletions

File tree

src/Adaptors/Requests/GetSynonymCollectionsAdaptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function process(): SynonymCollections
2525
{
2626
$synonymCollections = SynonymCollections::create();
2727

28-
foreach (array_keys($this->configuration->getIndexes()) as $engineSuffix) {
28+
foreach (array_keys($this->configuration->getIndexConfigurations()) as $engineSuffix) {
2929
$synonymCollections->add(SynonymCollection::create($engineSuffix));
3030
}
3131

src/Service/BifrostService.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public function __construct(Client $client, IndexConfiguration $configuration, D
7676
* @throws IndexingServiceException
7777
* @throws NotFoundExceptionInterface
7878
*/
79-
public function addDocument(DocumentInterface $document): ?string
79+
public function addDocument(DocumentInterface $document, array $indexSuffixes): ?string
8080
{
81-
$processedIds = $this->addDocuments([$document]);
81+
$processedIds = $this->addDocuments([$document], $indexSuffixes);
8282

8383
return array_shift($processedIds);
8484
}
@@ -88,12 +88,18 @@ public function addDocument(DocumentInterface $document): ?string
8888
* @throws IndexingServiceException
8989
* @throws NotFoundExceptionInterface
9090
*/
91-
public function addDocuments(array $documents): array
91+
public function addDocuments(array $documents, array $indexSuffixes): array
9292
{
9393
$documentMap = $this->getContentMapForDocuments($documents);
9494
$processedIds = [];
9595

96-
foreach ($documentMap as $indexSuffix => $docsToAdd) {
96+
foreach ($indexSuffixes as $indexSuffix) {
97+
$docsToAdd = $documentMap[$indexSuffix] ?? null;
98+
99+
if (!$docsToAdd) {
100+
continue;
101+
}
102+
97103
$response = $this->getClient()->documentsPost(
98104
$this->getConfiguration()->environmentizeIndex($indexSuffix),
99105
$docsToAdd
@@ -112,17 +118,17 @@ public function addDocuments(array $documents): array
112118
return array_unique($processedIds);
113119
}
114120

115-
public function removeDocument(DocumentInterface $document): ?string
121+
public function removeDocument(DocumentInterface $document, array $indexSuffixes): ?string
116122
{
117-
$processedIds = $this->removeDocuments([$document]);
123+
$processedIds = $this->removeDocuments([$document], $indexSuffixes);
118124

119125
return array_shift($processedIds);
120126
}
121127

122128
/**
123129
* @param DocumentInterface[] $documents
124130
*/
125-
public function removeDocuments(array $documents): array
131+
public function removeDocuments(array $documents, array $indexSuffixes): array
126132
{
127133
$documentMap = [];
128134
$processedIds = [];
@@ -136,9 +142,7 @@ public function removeDocuments(array $documents): array
136142
));
137143
}
138144

139-
$indexes = $this->getConfiguration()->getIndexesForDocument($document);
140-
141-
foreach (array_keys($indexes) as $indexSuffix) {
145+
foreach ($indexSuffixes as $indexSuffix) {
142146
if (!isset($documentMap[$indexSuffix])) {
143147
$documentMap[$indexSuffix] = [];
144148
}
@@ -233,7 +237,7 @@ public function getDocuments(array $ids): array
233237
{
234238
$docs = [];
235239

236-
foreach (array_keys($this->getConfiguration()->getIndexes()) as $indexSuffix) {
240+
foreach (array_keys($this->getConfiguration()->getIndexConfigurations()) as $indexSuffix) {
237241
// This is going to return results as a stdClass
238242
$response = $this->getClient()->documentsGet(
239243
$this->getConfiguration()->environmentizeIndex($indexSuffix),
@@ -335,7 +339,7 @@ public function configure(): array
335339
{
336340
$schemas = [];
337341

338-
foreach (array_keys($this->getConfiguration()->getIndexes()) as $indexSuffix) {
342+
foreach (array_keys($this->getConfiguration()->getIndexConfigurations()) as $indexSuffix) {
339343
$this->validateIndexConfiguration($indexSuffix);
340344

341345
$indexName = $this->getConfiguration()->environmentizeIndex($indexSuffix);
@@ -532,7 +536,7 @@ private function getContentMapForDocuments(array $documents): array
532536
continue;
533537
}
534538

535-
$indexes = $this->getConfiguration()->getIndexesForDocument($document);
539+
$indexes = $this->getConfiguration()->getIndexConfigurationsForDocument($document);
536540

537541
if (!$indexes) {
538542
Injector::inst()->get(LoggerInterface::class)->warn(

tests/Fake/IndexConfigurationFake.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public function shouldIncludePageHTML(): bool
3737
return $this->override['include_page_html'] ?? parent::shouldIncludePageHTML();
3838
}
3939

40-
public function getIndexes(): array
40+
public function getIndexConfigurations(): array
4141
{
42-
return $this->override['indexes'] ?? parent::getIndexes();
42+
return $this->override['indexes'] ?? parent::getIndexConfigurations();
4343
}
4444

4545
public function shouldUseSyncJobs(): bool
@@ -62,24 +62,24 @@ public function shouldTrackDependencies(): bool
6262
return $this->override['auto_dependency_tracking'] ?? parent::shouldTrackDependencies();
6363
}
6464

65-
public function getIndexesForClassName(string $class): array
65+
public function getIndexConfigurationsForClassName(string $class): array
6666
{
67-
return $this->override[__FUNCTION__][$class] ?? parent::getIndexesForClassName($class);
67+
return $this->override[__FUNCTION__][$class] ?? parent::getIndexConfigurationsForClassName($class);
6868
}
6969

70-
public function getIndexesForDocument(DocumentInterface $doc): array
70+
public function getIndexConfigurationsForDocument(DocumentInterface $doc): array
7171
{
72-
return $this->override[__FUNCTION__][$doc->getIdentifier()] ?? parent::getIndexesForDocument($doc);
72+
return $this->override[__FUNCTION__][$doc->getIdentifier()] ?? parent::getIndexConfigurationsForDocument($doc);
7373
}
7474

7575
public function isClassIndexed(string $class): bool
7676
{
7777
return $this->override[__FUNCTION__][$class] ?? parent::isClassIndexed($class);
7878
}
7979

80-
public function getClassesForIndex(string $index): array
80+
public function getClassesForIndex(string $indexSuffix): array
8181
{
82-
return $this->override[__FUNCTION__][$index] ?? parent::getClassesForIndex($index);
82+
return $this->override[__FUNCTION__][$indexSuffix] ?? parent::getClassesForIndex($indexSuffix);
8383
}
8484

8585
public function getSearchableClasses(): array

tests/Service/BifrostServiceTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ public function testAddDocuments(): void
702702
'321',
703703
];
704704

705-
$resultIds = $this->searchService->addDocuments($documents);
705+
$resultIds = $this->searchService->addDocuments($documents, ['content']);
706706

707707
$this->assertEqualsCanonicalizing($expectedIds, $resultIds);
708708
// And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
@@ -713,7 +713,7 @@ public function testAddDocuments(): void
713713
public function testAddDocumentsEmpty(): void
714714
{
715715
// Adding an empty array of documents, we would expect no API calls to be made
716-
$resultIds = $this->searchService->addDocuments([]);
716+
$resultIds = $this->searchService->addDocuments([], ['content']);
717717

718718
// We would expect the results to be empty
719719
$this->assertEqualsCanonicalizing([], $resultIds);
@@ -739,7 +739,7 @@ public function testAddDocument(): void
739739
// Append this mock response to our stack
740740
$this->mock->append(new Response(200, $headers, $body));
741741

742-
$resultId = $this->searchService->addDocument($document);
742+
$resultId = $this->searchService->addDocument($document, ['content']);
743743

744744
$this->assertEquals('doc-123', $resultId);
745745
// And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
@@ -763,7 +763,7 @@ public function testAddDocumentEmpty(): void
763763
$this->mock->append(new Response(200, $headers, $body));
764764

765765
// Kinda just checking that the array_shift correctly returns null if no results were presented from Bifrost
766-
$resultId = $this->searchService->addDocument($document);
766+
$resultId = $this->searchService->addDocument($document, ['content']);
767767

768768
$this->assertNull($resultId);
769769
// And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
@@ -819,7 +819,7 @@ public function testRemoveDocuments(): void
819819
'123',
820820
];
821821

822-
$resultIds = $this->searchService->addDocuments($documents);
822+
$resultIds = $this->searchService->addDocuments($documents, ['content']);
823823

824824
$this->assertEqualsCanonicalizing($expectedIds, $resultIds);
825825
// And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
@@ -830,7 +830,7 @@ public function testRemoveDocuments(): void
830830
public function testRemoveDocumentsEmpty(): void
831831
{
832832
// Removing an empty array of documents, we would expect no API calls to be made
833-
$resultIds = $this->searchService->removeDocuments([]);
833+
$resultIds = $this->searchService->removeDocuments([], ['content']);
834834

835835
// We would expect the results to be empty
836836
$this->assertEqualsCanonicalizing([], $resultIds);
@@ -858,7 +858,7 @@ public function testRemoveDocument(): void
858858

859859
$expectedId = sprintf('silverstripe_searchservice_tests_fake_dataobjectfake_%s', $documentOne->ID);
860860

861-
$resultId = $this->searchService->removeDocument($document);
861+
$resultId = $this->searchService->removeDocument($document, ['content']);
862862

863863
$this->assertEquals($expectedId, $resultId);
864864
// And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make
@@ -882,7 +882,7 @@ public function testRemoveDocumentEmpty(): void
882882
$this->mock->append(new Response(200, $headers, $body));
883883

884884
// Kinda just checking that the array_shift correctly returns null if no results were presented from Bifrost
885-
$resultId = $this->searchService->removeDocument($document);
885+
$resultId = $this->searchService->removeDocument($document, ['content']);
886886

887887
$this->assertNull($resultId);
888888
// And make sure nothing is left in our Response Stack. This would indicate that every Request we expect to make

0 commit comments

Comments
 (0)