@@ -270,31 +270,28 @@ private function applyTaxonomyFilter(Filter $filter, WpQueryArgs $queryArgs): Wp
270
270
271
271
private function applySearchFilter (SearchKeywordFilter $ filter , WpQueryArgs $ queryArgs , ?string $ languageCode = null ): WpQueryArgs
272
272
{
273
- if (!$ languageCode ) {
274
- return $ queryArgs ->withMetaQueryItem (
275
- [
276
- 'relation ' => 'OR ' ,
277
- [
278
- 'key ' => 'fau_degree_program_searchable_content_ ' . MultilingualString::EN ,
279
- 'value ' => $ filter ->value (),
280
- 'compare ' => 'LIKE ' ,
281
- ],
282
- [
283
- 'key ' => 'fau_degree_program_searchable_content_ ' . MultilingualString::DE ,
284
- 'value ' => $ filter ->value (),
285
- 'compare ' => 'LIKE ' ,
286
- ],
287
- ]
288
- );
289
- }
273
+ $ keywords = array_filter (array_map ('trim ' , explode (' ' , $ filter ->value ())));
274
+ $ metaKeyPrefix = 'fau_degree_program_searchable_content_ ' ;
275
+ $ metaKeys = $ languageCode
276
+ ? [$ metaKeyPrefix . $ languageCode ]
277
+ : [$ metaKeyPrefix . MultilingualString::EN , $ metaKeyPrefix . MultilingualString::DE ];
278
+
279
+ $ metaQuery = array_reduce ($ keywords , static function ($ metaQuery , $ keyword ) use ($ metaKeys ): array {
280
+ $ keywordConditions = array_values (array_map (
281
+ static fn ($ key ) => [
282
+ 'key ' => $ key ,
283
+ 'value ' => $ keyword ,
284
+ 'compare ' => 'LIKE ' ,
285
+ ],
286
+ $ metaKeys
287
+ ));
290
288
291
- return $ queryArgs ->withMetaQueryItem (
292
- [
293
- 'key ' => 'fau_degree_program_searchable_content_ ' . $ languageCode ,
294
- 'value ' => $ filter ->value (),
295
- 'compare ' => 'LIKE ' ,
296
- ]
297
- );
289
+ $ metaQuery [] = ['relation ' => 'OR ' ] + $ keywordConditions ;
290
+
291
+ return $ metaQuery ;
292
+ }, ['relation ' => 'AND ' ]);
293
+
294
+ return $ queryArgs ->withMetaQueryItem ($ metaQuery );
298
295
}
299
296
300
297
private function currentTerm (CollectionCriteria $ criteria ): ?WP_Term
0 commit comments