Skip to content

Commit 42d9943

Browse files
committed
feat(doctrine): add SearchFilter STRATEGY_PATTERN
1 parent d3b4b7b commit 42d9943

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/Doctrine/Common/Filter/SearchFilterInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,14 @@ interface SearchFilterInterface
7070
* @var string Finds fields that are starting with the word case-insensitive
7171
*/
7272
public const STRATEGY_IWORD_START = 'iword_start';
73+
74+
/**
75+
* @var string Finds fields that match the user-specified pattern
76+
*/
77+
public const STRATEGY_PATTERN = 'pattern';
78+
79+
/**
80+
* @var string Finds fields that match the user-specified pattern case-insensitive
81+
*/
82+
public const STRATEGY_IPATTERN = 'ipattern';
7383
}

src/Doctrine/Odm/Filter/SearchFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ private function getEqualityMatchStrategyValue(string $strategy, string $field,
276276
self::STRATEGY_START => new Regex("^$quotedValue", $caseSensitive ? '' : 'i'),
277277
self::STRATEGY_END => new Regex("$quotedValue$", $caseSensitive ? '' : 'i'),
278278
self::STRATEGY_WORD_START => new Regex("(^$quotedValue.*|.*\s$quotedValue.*)", $caseSensitive ? '' : 'i'),
279+
self::STRATEGY_PATTERN => throw new InvalidArgumentException(\sprintf('strategy %s is not implemented.', $strategy)),
279280
default => throw new InvalidArgumentException(\sprintf('strategy %s does not exist.', $strategy)),
280281
};
281282
}

src/Doctrine/Orm/Filter/SearchFilter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
334334
$wrapCase((string) $queryBuilder->expr()->concat("'% '", $keyValueParameter, "'%'"))
335335
)
336336
),
337+
self::STRATEGY_PATTERN => $queryBuilder->expr()->like(
338+
$wrapCase($aliasedField),
339+
$wrapCase($keyValueParameter)
340+
),
337341
default => throw new InvalidArgumentException(\sprintf('strategy %s does not exist.', $strategy)),
338342
};
339343
}

0 commit comments

Comments
 (0)