Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion features/doctrine/search_filter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Feature: Search filter on collections
},
"hydra:search": {
"@type": "hydra:IriTemplate",
"hydra:template": "/dummy_cars{?availableAt[before],availableAt[strictly_before],availableAt[after],availableAt[strictly_after],canSell,foobar[],foobargroups[],foobargroups_override[],colors.prop,colors,colors[],secondColors,secondColors[],thirdColors,thirdColors[],uuid,uuid[],name}",
"hydra:template": "/dummy_cars{?availableAt[before],availableAt[strictly_before],availableAt[after],availableAt[strictly_after],canSell,foobar[],foobargroups[],foobargroups_override[],colors.prop,colors,colors[],secondColors,secondColors[],thirdColors,thirdColors[],uuid,uuid[],name,brand,brand[]}",
"hydra:variableRepresentation": "BasicRepresentation",
"hydra:mapping": [
{
Expand Down Expand Up @@ -186,6 +186,18 @@ Feature: Search filter on collections
"variable": "name",
"property": "name",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "brand",
"property": "brand",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "brand[]",
"property": "brand",
"required": false
}
]
}
Expand Down
25 changes: 25 additions & 0 deletions src/Doctrine/Common/Filter/SearchFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,48 @@ interface SearchFilterInterface
*/
public const STRATEGY_EXACT = 'exact';

/**
* @var string Exact matching case-insensitive
*/
public const STRATEGY_IEXACT = 'iexact';

/**
* @var string The value must be contained in the field
*/
public const STRATEGY_PARTIAL = 'partial';

/**
* @var string The value must be contained in the field case-insensitive
*/
public const STRATEGY_IPARTIAL = 'partial';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't thisd be ipartial?


/**
* @var string Finds fields that are starting with the value
*/
public const STRATEGY_START = 'start';

/**
* @var string Finds fields that are starting with the value case-insensitive
*/
public const STRATEGY_ISTART = 'start';

/**
* @var string Finds fields that are ending with the value
*/
public const STRATEGY_END = 'end';

/**
* @var string Finds fields that are ending with the value case-insensitive
*/
public const STRATEGY_IEND = 'end';

/**
* @var string Finds fields that are starting with the word
*/
public const STRATEGY_WORD_START = 'word_start';

/**
* @var string Finds fields that are starting with the word case-insensitive
*/
public const STRATEGY_IWORD_START = 'word_start';
}
2 changes: 1 addition & 1 deletion src/Doctrine/Common/Filter/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getDescription(string $resourceClass): array
$strategy = $this->getProperties()[$property] ?? self::STRATEGY_EXACT;
$filterParameterNames = [$propertyName];

if (self::STRATEGY_EXACT === $strategy) {
if (\in_array($strategy, [self::STRATEGY_EXACT, self::STRATEGY_IEXACT], true)) {
$filterParameterNames[] = $propertyName.'[]';
}

Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/Document/DummyCar.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class DummyCar
private ?bool $canSell = null;
#[ODM\Field(type: 'date')]
private ?\DateTime $availableAt = null;
#[ApiFilter(SearchFilter::class, strategy: SearchFilter::STRATEGY_IEXACT)]
#[Serializer\Groups(['colors'])]
#[Serializer\SerializedName('carBrand')]
#[ODM\Field]
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/Entity/DummyCar.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class DummyCar
private bool $canSell;
#[ORM\Column(type: 'datetime')]
private \DateTime $availableAt;
#[ApiFilter(SearchFilter::class, strategy: SearchFilter::STRATEGY_IEXACT)]
#[Serializer\Groups(['colors'])]
#[Serializer\SerializedName('carBrand')]
#[ORM\Column]
Expand Down