@@ -183,6 +183,13 @@ class ScoreStrategy implements HttpTransportable
183
183
*/
184
184
private $ filter ;
185
185
186
+ /**
187
+ * Filters.
188
+ *
189
+ * @var Filter[]
190
+ */
191
+ private $ filters = [];
192
+
186
193
/**
187
194
* @var float
188
195
*
@@ -256,6 +263,14 @@ public function getFilter(): ? Filter
256
263
return $ this ->filter ;
257
264
}
258
265
266
+ /**
267
+ * @return Filter[]
268
+ */
269
+ public function getFilters (): array
270
+ {
271
+ return $ this ->filters ;
272
+ }
273
+
259
274
/**
260
275
* Create empty.
261
276
*
@@ -267,8 +282,6 @@ public static function createDefault(): ScoreStrategy
267
282
}
268
283
269
284
/**
270
- * Create default field scoring.
271
- *
272
285
* @param string $field
273
286
* @param float $factor
274
287
* @param float $missing
@@ -302,8 +315,6 @@ public static function createFieldBoosting(
302
315
}
303
316
304
317
/**
305
- * Create custom function scoring.
306
- *
307
318
* @param string $function
308
319
* @param float $weight
309
320
* @param Filter $filter
@@ -328,8 +339,6 @@ public static function createCustomFunction(
328
339
}
329
340
330
341
/**
331
- * Create custom function scoring.
332
- *
333
342
* @param float $weight
334
343
* @param Filter $filter
335
344
* @param bool $matchMainQuery
@@ -350,6 +359,29 @@ public static function createWeightFunction(
350
359
return $ scoreStrategy ;
351
360
}
352
361
362
+ /**
363
+ * @param float $weight
364
+ * @param Filter[] $filters
365
+ * @param bool $matchMainQuery
366
+ *
367
+ * @return ScoreStrategy
368
+ */
369
+ public static function createWeightMultiFilterFunction (
370
+ float $ weight = self ::DEFAULT_WEIGHT ,
371
+ array $ filters = [],
372
+ bool $ matchMainQuery = true
373
+ ): ScoreStrategy {
374
+ $ scoreStrategy = self ::createDefault ();
375
+ $ scoreStrategy ->type = 'weight ' ;
376
+ $ scoreStrategy ->weight = $ weight ;
377
+ $ scoreStrategy ->filters = array_map (function (Filter $ filter ) {
378
+ return self ::fixFilterFieldPath ($ filter );
379
+ }, $ filters );
380
+ $ scoreStrategy ->configuration ['match_main_query ' ] = $ matchMainQuery ;
381
+
382
+ return $ scoreStrategy ;
383
+ }
384
+
353
385
/**
354
386
* Create custom function scoring.
355
387
*
@@ -427,6 +459,9 @@ public function toArray(): array
427
459
->filter
428
460
->toArray ()
429
461
: null ),
462
+ 'filters ' => array_map (function (Filter $ filter ) {
463
+ return $ filter ->toArray ();
464
+ }, $ this ->filters ),
430
465
];
431
466
}
432
467
@@ -448,6 +483,10 @@ public static function createFromArray(array $array)
448
483
? Filter::createFromArray ($ array ['filter ' ])
449
484
: null ;
450
485
486
+ $ scoreStrategy ->filters = array_map (function (array $ filterAsArray ) {
487
+ return Filter::createFromArray ($ filterAsArray );
488
+ }, $ array ['filters ' ] ?? []);
489
+
451
490
return $ scoreStrategy ;
452
491
}
453
492
}
0 commit comments