@@ -87,12 +87,17 @@ protected function filterProperty(string $property, $value, Builder $aggregation
87
87
[$ matchField , $ field , $ associations ] = $ this ->addLookupsForNestedProperty ($ property , $ aggregationBuilder , $ resourceClass );
88
88
}
89
89
90
- /**
91
- * @var MongoDBClassMetadata
92
- */
93
- $ metadata = $ this ->getNestedMetadata ($ resourceClass , $ associations );
94
-
95
90
$ caseSensitive = true ;
91
+ $ strategy = $ this ->properties [$ property ] ?? self ::STRATEGY_EXACT ;
92
+
93
+ // prefixing the strategy with i makes it case insensitive
94
+ if (0 === strpos ($ strategy , 'i ' )) {
95
+ $ strategy = substr ($ strategy , 1 );
96
+ $ caseSensitive = false ;
97
+ }
98
+
99
+ /** @var MongoDBClassMetadata */
100
+ $ metadata = $ this ->getNestedMetadata ($ resourceClass , $ associations );
96
101
97
102
if ($ metadata ->hasField ($ field ) && !$ metadata ->hasAssociation ($ field )) {
98
103
if ('id ' === $ field ) {
@@ -107,23 +112,9 @@ protected function filterProperty(string $property, $value, Builder $aggregation
107
112
return ;
108
113
}
109
114
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
-
118
- $ inValues = [];
119
- foreach ($ values as $ inValue ) {
120
- $ inValues [] = $ this ->addEqualityMatchStrategy ($ strategy , $ field , $ inValue , $ caseSensitive , $ metadata );
121
- }
115
+ $ this ->addEqualityMatchStrategy ($ strategy , $ aggregationBuilder , $ matchField , $ values , $ caseSensitive , $ metadata );
122
116
123
- $ aggregationBuilder
124
- ->match ()
125
- ->field ($ matchField )
126
- ->in ($ inValues );
117
+ return ;
127
118
}
128
119
129
120
// metadata doesn't have the field, nor an association on the field
@@ -132,7 +123,6 @@ protected function filterProperty(string $property, $value, Builder $aggregation
132
123
}
133
124
134
125
$ values = array_map ([$ this , 'getIdFromValue ' ], $ values );
135
- $ associationFieldIdentifier = 'id ' ;
136
126
$ doctrineTypeField = $ this ->getDoctrineFieldType ($ property , $ resourceClass );
137
127
138
128
if (null !== $ this ->identifiersExtractor ) {
@@ -149,20 +139,33 @@ protected function filterProperty(string $property, $value, Builder $aggregation
149
139
return ;
150
140
}
151
141
142
+ $ this ->addEqualityMatchStrategy ($ strategy , $ aggregationBuilder , $ matchField , $ values , $ caseSensitive , $ metadata );
143
+ }
144
+
145
+ /**
146
+ * Add equality match stage according to the strategy.
147
+ */
148
+ private function addEqualityMatchStrategy (string $ strategy , Builder $ aggregationBuilder , string $ matchField , $ values , bool $ caseSensitive , ClassMetadata $ metadata ): void
149
+ {
150
+ $ inValues = [];
151
+ foreach ($ values as $ inValue ) {
152
+ $ inValues [] = $ this ->getEqualityMatchStrategyValue ($ strategy , $ matchField , $ inValue , $ caseSensitive , $ metadata );
153
+ }
154
+
152
155
$ aggregationBuilder
153
156
->match ()
154
157
->field ($ matchField )
155
- ->in ($ values );
158
+ ->in ($ inValues );
156
159
}
157
160
158
161
/**
159
- * Add equality match stage according to the strategy.
162
+ * Get equality match value according to the strategy.
160
163
*
161
164
* @throws InvalidArgumentException If strategy does not exist
162
165
*
163
166
* @return Regex|string
164
167
*/
165
- private function addEqualityMatchStrategy (string $ strategy , string $ field , $ value , bool $ caseSensitive , ClassMetadata $ metadata )
168
+ private function getEqualityMatchStrategyValue (string $ strategy , string $ field , $ value , bool $ caseSensitive , ClassMetadata $ metadata )
166
169
{
167
170
$ type = $ metadata ->getTypeOfField ($ field );
168
171
0 commit comments