Skip to content

Commit

Permalink
Merge pull request #4 from lmc-eu/feature/use-placeholder-for-all-fields
Browse files Browse the repository at this point in the history
Feature/use placeholder for all fields
  • Loading branch information
MortalFlesh authored Mar 29, 2022
2 parents 5350987 + b6741d1 commit 117089f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- There should always be "Unreleased" section at the beginning. -->

## Unreleased
- Use `*` as a placeholder for all fields in `EntityApplicator`

## 1.2.0 - 2021-08-10
- Add an `$initiator` to `ResponseDecoders` `supports` method
Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "*",
Expand All @@ -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/"
Expand All @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/QueryBuilder/Applicator/EntityApplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
15 changes: 15 additions & 0 deletions tests/QueryBuilder/Applicator/EntityApplicatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 4 additions & 2 deletions tests/QueryBuilder/Fixture/BaseDummyEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +24,7 @@ public function getNumberOfRows(): int

public function getFields(): array
{
return ['jds', '*', 'score'];
return $this->fields;
}

public function getKeywords(): array
Expand Down
20 changes: 10 additions & 10 deletions tests/QueryBuilder/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -128,7 +128,7 @@ public function provideEntity(): array
[
'start=0',
'rows=10',
'fl=&',
'fl=' . urlencode('*'),
$defaultEmptyQuery,
'fq=' . urlencode('{!tag=filter-tag}filter:query'),
],
Expand All @@ -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'),
Expand All @@ -149,7 +149,7 @@ public function provideEntity(): array
[
'start=0',
'rows=20',
'fl=&',
'fl=' . urlencode('*'),
'q=' . urlencode('key word'),
'defType=edismax',
'q.alt=' . urlencode('*:*'),
Expand All @@ -165,7 +165,7 @@ public function provideEntity(): array
[
'start=0',
'rows=20',
'fl=&',
'fl=' . urlencode('*'),
'q=' . urlencode('key word'),
'defType=edismax',
'q.alt=' . urlencode('*:*'),
Expand All @@ -182,7 +182,7 @@ public function provideEntity(): array
[
'start=0',
'rows=20',
'fl=&',
'fl=' . urlencode('*'),
'q=' . urlencode('key word'),
'defType=edismax',
'q.alt=' . urlencode('*:*'),
Expand All @@ -200,7 +200,7 @@ public function provideEntity(): array
[
'start=0',
'rows=20',
'fl=&',
'fl=' . urlencode('*'),
$defaultEmptyQuery,
'group=true',
'group.field=grouping-field',
Expand All @@ -214,7 +214,7 @@ public function provideEntity(): array
[
'start=0',
'rows=20',
'fl=&',
'fl=' . urlencode('*'),
$defaultEmptyQuery,
'group=true',
'group.field=grouping-field',
Expand All @@ -238,7 +238,7 @@ public function provideEntity(): array
[
'start=0',
'rows=20',
'fl=&',
'fl=' . urlencode('*'),
$defaultEmptyQuery,
'sort=' . urlencode('score desc,field asc'),
],
Expand All @@ -257,7 +257,7 @@ public function provideEntity(): array
[
'start=0',
'rows=20',
'fl=&',
'fl=' . urlencode('*'),
'q=' . urlencode('key word'),
'q.op=AND',
],
Expand Down

0 comments on commit 117089f

Please sign in to comment.