Skip to content

Commit c528404

Browse files
committed
SearchFilter: Allow strategy on associations (ODM)
1 parent b21d5f7 commit c528404

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilter.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ protected function filterProperty(string $property, $value, Builder $aggregation
9494

9595
$caseSensitive = true;
9696

97+
$strategy = $this->properties[$property] ?? self::STRATEGY_EXACT;
98+
99+
// prefixing the strategy with i makes it case insensitive
100+
if (0 === strpos($strategy, 'i')) {
101+
$strategy = substr($strategy, 1);
102+
$caseSensitive = false;
103+
}
104+
97105
if ($metadata->hasField($field) && !$metadata->hasAssociation($field)) {
98106
if ('id' === $field) {
99107
$values = array_map([$this, 'getIdFromValue'], $values);
@@ -107,17 +115,10 @@ protected function filterProperty(string $property, $value, Builder $aggregation
107115
return;
108116
}
109117

110-
$strategy = $this->properties[$property] ?? self::STRATEGY_EXACT;
111-
112-
// prefixing the strategy with i makes it case insensitive
113-
if (0 === strpos($strategy, 'i')) {
114-
$strategy = substr($strategy, 1);
115-
$caseSensitive = false;
116-
}
117-
118118
$inValues = [];
119+
$type = $metadata->getTypeOfField($field);
119120
foreach ($values as $inValue) {
120-
$inValues[] = $this->addEqualityMatchStrategy($strategy, $field, $inValue, $caseSensitive, $metadata);
121+
$inValues[] = $this->addEqualityMatchStrategy($strategy, $field, $inValue, $caseSensitive, $type);
121122
}
122123

123124
$aggregationBuilder
@@ -149,10 +150,15 @@ protected function filterProperty(string $property, $value, Builder $aggregation
149150
return;
150151
}
151152

153+
$inValues = [];
154+
foreach ($values as $inValue) {
155+
$inValues[] = $this->addEqualityMatchStrategy($strategy, $field, $inValue, $caseSensitive, $doctrineTypeField);
156+
}
157+
152158
$aggregationBuilder
153159
->match()
154160
->field($matchField)
155-
->in($values);
161+
->in($inValues);
156162
}
157163

158164
/**
@@ -162,10 +168,8 @@ protected function filterProperty(string $property, $value, Builder $aggregation
162168
*
163169
* @return Regex|string
164170
*/
165-
private function addEqualityMatchStrategy(string $strategy, string $field, $value, bool $caseSensitive, ClassMetadata $metadata)
171+
private function addEqualityMatchStrategy(string $strategy, string $field, $value, bool $caseSensitive, string $type)
166172
{
167-
$type = $metadata->getTypeOfField($field);
168-
169173
switch ($strategy) {
170174
case MongoDbType::STRING !== $type:
171175
return MongoDbType::getType($type)->convertToDatabaseValue($value);

0 commit comments

Comments
 (0)