diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bbe299..65cd3c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased +- Use `*` as a placeholder for all fields in `EntityApplicator` ## 1.2.0 - 2021-08-10 - Add an `$initiator` to `ResponseDecoders` `supports` method diff --git a/composer.json b/composer.json index 6a66171..47f801e 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "lmc/cqrs-solr", - "type": "library", "description": "A library containing base implementations to help with Solr Queries and Commands", "license": "MIT", + "type": "library", "require": { "php": "^7.4", "ext-json": "*", @@ -20,9 +20,6 @@ "phpstan/phpstan-phpunit": "^0.12.18", "phpunit/phpunit": "^9.5" }, - "config": { - "sort-packages": true - }, "autoload": { "psr-4": { "Lmc\\Cqrs\\Solr\\": "src/" @@ -33,6 +30,14 @@ "Lmc\\Cqrs\\Solr\\": "tests/" } }, + "config": { + "allow-plugins": { + "ergebnis/composer-normalize": true, + "phpstan/extension-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true + }, + "sort-packages": true + }, "scripts": { "all": [ "@lint", diff --git a/src/QueryBuilder/Applicator/EntityApplicator.php b/src/QueryBuilder/Applicator/EntityApplicator.php index 4af6512..3fc1851 100644 --- a/src/QueryBuilder/Applicator/EntityApplicator.php +++ b/src/QueryBuilder/Applicator/EntityApplicator.php @@ -21,8 +21,12 @@ public function setEntity(EntityInterface $entity): void public function applyOnQuery(Query $query): void { + $fields = empty($fields = $this->entity->getFields()) + ? '*' + : $fields; + $query ->setRows($this->entity->getNumberOfRows()) - ->setFields($this->entity->getFields()); + ->setFields($fields); } } diff --git a/tests/QueryBuilder/Applicator/EntityApplicatorTest.php b/tests/QueryBuilder/Applicator/EntityApplicatorTest.php index 99303fb..ee67128 100644 --- a/tests/QueryBuilder/Applicator/EntityApplicatorTest.php +++ b/tests/QueryBuilder/Applicator/EntityApplicatorTest.php @@ -27,4 +27,19 @@ public function shouldApplyEntityInterface(): void $this->assertStringContainsString('rows=' . $baseEntity->getNumberOfRows(), $queryUri); $this->assertStringContainsString('fl=' . implode(',', $baseEntity->getFields()), $queryUri); } + + /** + * @test + */ + public function shouldUsePlaceholderForAllFields(): void + { + $baseEntity = new BaseDummyEntity('', []); + $this->assertTrue($this->entityApplicator->supportEntity($baseEntity)); + $this->entityApplicator->setEntity($baseEntity); + + $queryUri = $this->getCustomQueryUri([$this->entityApplicator]); + + $this->assertStringContainsString('rows=' . $baseEntity->getNumberOfRows(), $queryUri); + $this->assertStringContainsString('fl=*', $queryUri); + } } diff --git a/tests/QueryBuilder/Fixture/BaseDummyEntity.php b/tests/QueryBuilder/Fixture/BaseDummyEntity.php index 7c5ca6c..06b56f8 100644 --- a/tests/QueryBuilder/Fixture/BaseDummyEntity.php +++ b/tests/QueryBuilder/Fixture/BaseDummyEntity.php @@ -9,10 +9,12 @@ class BaseDummyEntity implements EntityInterface, FulltextInterface { private string $query; + private array $fields; - public function __construct(string $query = '') + public function __construct(string $query = '', array $fields = ['jds', '*', 'score']) { $this->query = $query; + $this->fields = $fields; } public function getNumberOfRows(): int @@ -22,7 +24,7 @@ public function getNumberOfRows(): int public function getFields(): array { - return ['jds', '*', 'score']; + return $this->fields; } public function getKeywords(): array diff --git a/tests/QueryBuilder/QueryBuilderTest.php b/tests/QueryBuilder/QueryBuilderTest.php index d8778ad..910074f 100644 --- a/tests/QueryBuilder/QueryBuilderTest.php +++ b/tests/QueryBuilder/QueryBuilderTest.php @@ -110,7 +110,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), $defaultEmptyQuery, 'facet.field=' . urlencode('{!key=facet-field ex=global-exclude,facet-field-exclude}field'), 'f.field.facet.limit=60', @@ -128,7 +128,7 @@ public function provideEntity(): array [ 'start=0', 'rows=10', - 'fl=&', + 'fl=' . urlencode('*'), $defaultEmptyQuery, 'fq=' . urlencode('{!tag=filter-tag}filter:query'), ], @@ -138,7 +138,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), $defaultEmptyQuery, 'fq=' . urlencode('{!tag=global-tags,filter-1-tag}fitler1:"value"'), 'fq=' . urlencode('{!tag=global-tags}fitler2:"value'), @@ -149,7 +149,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), 'q=' . urlencode('key word'), 'defType=edismax', 'q.alt=' . urlencode('*:*'), @@ -165,7 +165,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), 'q=' . urlencode('key word'), 'defType=edismax', 'q.alt=' . urlencode('*:*'), @@ -182,7 +182,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), 'q=' . urlencode('key word'), 'defType=edismax', 'q.alt=' . urlencode('*:*'), @@ -200,7 +200,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), $defaultEmptyQuery, 'group=true', 'group.field=grouping-field', @@ -214,7 +214,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), $defaultEmptyQuery, 'group=true', 'group.field=grouping-field', @@ -238,7 +238,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), $defaultEmptyQuery, 'sort=' . urlencode('score desc,field asc'), ], @@ -257,7 +257,7 @@ public function provideEntity(): array [ 'start=0', 'rows=20', - 'fl=&', + 'fl=' . urlencode('*'), 'q=' . urlencode('key word'), 'q.op=AND', ],