66
77use Erichard \ElasticQueryBuilder \Contracts \QueryInterface ;
88use Erichard \ElasticQueryBuilder \Features \HasBoost ;
9+ use Erichard \ElasticQueryBuilder \Features \HasFuzziness ;
910use Erichard \ElasticQueryBuilder \Features \HasMinimumShouldMatch ;
1011use Erichard \ElasticQueryBuilder \Features \HasOperator ;
1112
@@ -14,6 +15,7 @@ class MultiMatchQuery implements QueryInterface
1415 use HasOperator;
1516 use HasBoost;
1617 use HasMinimumShouldMatch;
18+ use HasFuzziness;
1719
1820 /**
1921 * @param mixed[]|string[] $fields
@@ -22,14 +24,16 @@ public function __construct(
2224 protected array $ fields ,
2325 protected string $ query ,
2426 protected ?string $ type = null ,
25- protected ?string $ fuzziness = null ,
27+ ?string $ fuzziness = null ,
2628 ?string $ operator = null ,
2729 ?float $ boost = null ,
28- ?string $ minimumShouldMatch = null
30+ ?string $ minimumShouldMatch = null ,
31+ protected array $ params = [],
2932 ) {
3033 $ this ->operator = $ operator ;
3134 $ this ->boost = $ boost ;
3235 $ this ->minimumShouldMatch = $ minimumShouldMatch ;
36+ $ this ->fuzziness = $ fuzziness ;
3337 }
3438
3539 public function setFields (array $ fields ): self
@@ -53,9 +57,9 @@ public function setType(string $type): self
5357 return $ this ;
5458 }
5559
56- public function setFuzziness ( string $ fuzziness ): self
60+ public function setParams ( array $ params ): self
5761 {
58- $ this ->fuzziness = $ fuzziness ;
62+ $ this ->params = $ params ;
5963
6064 return $ this ;
6165 }
@@ -71,16 +75,14 @@ public function build(): array
7175 $ data ['type ' ] = $ this ->type ;
7276 }
7377
74- if (null !== $ this ->fuzziness ) {
75- $ data ['fuzziness ' ] = $ this ->fuzziness ;
76- }
77-
7878 $ this ->buildOperatorTo ($ data );
7979 $ this ->buildBoostTo ($ data );
8080 $ this ->buildMinimumShouldMatchTo ($ data );
81+ $ this ->buildFuzzinessTo ($ data );
8182
82- return [
83- 'multi_match ' => $ data ,
84- ];
83+ $ build = $ this ->params ;
84+ $ build ['multi_match ' ] = $ data ;
85+
86+ return $ build ;
8587 }
8688}
0 commit comments