Skip to content

Commit

Permalink
[Pipeline] #1245170 - Prevent empty pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreGauthier committed Sep 19, 2024
1 parent 092cc71 commit 6bca420
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 24 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": ">=8.2",
"api-platform/core": "^3.2",
"api-platform/core": "~3.3.0",
"cweagans/composer-patches": "^1.7",
"opensearch-project/opensearch-php": "^2.1",
"lexik/jwt-authentication-bundle": "^2.14",
Expand Down
6 changes: 4 additions & 2 deletions src/Index/Service/IndexSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,11 @@ public function getDynamicIndexSettings(Metadata $metadata, LocalizedCatalog|int
$complexeSourceField = $this->sourceFieldRepository->getComplexeFields($metadata);
$settings += ['mapping.nested_fields.limit' => \count($complexeSourceField)];

// Add default pipeline
// Add default pipeline if any processor are defined.
$pipeline = $this->pipelineRepository->createByMetadata($metadata);
$settings['default_pipeline'] = $pipeline->getName();
if ($pipeline) {
$settings['default_pipeline'] = $pipeline->getName();
}

return $settings;
}
Expand Down
9 changes: 4 additions & 5 deletions src/Index/Tests/Unit/IndexSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class IndexSettingsTest extends AbstractTestCase
*
* @dataProvider dynamicAttributeDataProvider
*/
public function testDynamicIndexSettings(string $fieldName, int $expectedNestedFieldsLimit, string $expectedDefaultPipeline)
public function testDynamicIndexSettings(string $fieldName, int $expectedNestedFieldsLimit)
{
static::loadFixture(
[
Expand All @@ -43,15 +43,14 @@ public function testDynamicIndexSettings(string $fieldName, int $expectedNestedF
$settings = $indexSettings->getDynamicIndexSettings($metadata, $localizedCatalogs);

$this->assertEquals($expectedNestedFieldsLimit, $settings['mapping.nested_fields.limit']);
$this->assertEquals($expectedDefaultPipeline, $settings['default_pipeline']);
}

protected function dynamicAttributeDataProvider(): array
{
return [
['source_field_1.yaml', 0, 'test-gally-llm-pipeline-product'],
['source_field_2.yaml', 2, 'test-gally-llm-pipeline-product'],
['source_field_3.yaml', 4, 'test-gally-llm-pipeline-product'],
['source_field_1.yaml', 0],
['source_field_2.yaml', 2],
['source_field_3.yaml', 4],
];
}
}
6 changes: 4 additions & 2 deletions src/Search/Repository/Ingest/PipelineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function get(string $name): ?IngestPipeline
/**
* @throws \Exception
*/
public function createByMetadata(Metadata $metadata): IngestPipeline
public function createByMetadata(Metadata $metadata): ?IngestPipeline
{
$pipelineName = $this->pipelinePrefix . $metadata->getEntity();
$processors = [];
Expand All @@ -72,6 +72,8 @@ public function createByMetadata(Metadata $metadata): IngestPipeline
$processors = array_merge($processors, $processorsProvider->getProcessors($metadata));
}

return $this->create($pipelineName, $pipelineName, $processors);
return empty($processors)
? null
: $this->create($pipelineName, $pipelineName, $processors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ public function get(string $name): ?IngestPipeline;
*
* @param Metadata $metadata metadata
*/
public function createByMetadata(Metadata $metadata): IngestPipeline;
public function createByMetadata(Metadata $metadata): ?IngestPipeline;
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,6 @@ public function testCreateByMetadata(): void
[]
);
$actualPipeline = $ingestPipelineRepository->createByMetadata($metadataRepository->findByEntity('category'));
$this->assertEquals($expectedPipeline->getName(), $actualPipeline->getName());
$this->assertEquals($expectedPipeline->getDescription(), $actualPipeline->getDescription());
$this->assertGreaterThanOrEqual(\count($expectedPipeline->getProcessors()), \count($actualPipeline->getProcessors()));

$expectedPipeline = new IngestPipeline(
'test-gally-llm-pipeline-product_document',
'test-gally-llm-pipeline-product_document',
[]
);
$actualPipeline = $ingestPipelineRepository->createByMetadata($metadataRepository->findByEntity('product_document'));
$this->assertEquals($expectedPipeline->getName(), $actualPipeline->getName());
$this->assertEquals($expectedPipeline->getDescription(), $actualPipeline->getDescription());
$this->assertGreaterThanOrEqual(\count($expectedPipeline->getProcessors()), \count($actualPipeline->getProcessors()));
$this->assertNull($actualPipeline);
}
}

0 comments on commit 6bca420

Please sign in to comment.