@@ -141,7 +141,7 @@ public function testMatch(string|MatchOptions $options, array $expected): void
141141 {
142142 $ dsl = BoolQueryBuilder::make ()->whereMatch ('name ' , 'foo ' , $ options )->toDSL ();
143143
144- $ this ->assertArrayFragment (array_merge (['query ' => 'foo ' ], $ expected ), $ dsl );
144+ $ this ->assertArrayFragment ([ ' must ' => [[ " match " => [ ' name ' => array_merge (['query ' => 'foo ' ], $ expected )]]]] , $ dsl );
145145 }
146146
147147 public function provideMatch (): array
@@ -160,6 +160,32 @@ public function provideMatch(): array
160160 ];
161161 }
162162
163+ /**
164+ * @dataProvider provideOrMatch
165+ */
166+ public function testOrMatch (string |MatchOptions $ options , array $ expected ): void
167+ {
168+ $ dsl = BoolQueryBuilder::make ()->orWhereMatch ('name ' , 'foo ' , $ options )->toDSL ();
169+
170+ $ this ->assertArrayFragment (['should ' => [["match " => ['name ' => array_merge (['query ' => 'foo ' ], $ expected )]]]], $ dsl );
171+ }
172+
173+ public function provideOrMatch (): array
174+ {
175+ return [
176+ 'operator ' => ['and ' , ['operator ' => 'and ' ]],
177+ 'fuzziness ' => [MatchOptions::make (fuzziness: 'AUTO ' ), ['fuzziness ' => 'AUTO ' ]],
178+ 'minimum_should_match ' => [
179+ MatchOptions::make (minimumShouldMatch: '50% ' ),
180+ ['minimum_should_match ' => '50% ' ],
181+ ],
182+ 'many options ' => [
183+ MatchOptions::make (operator: 'or ' , fuzziness: '2 ' , minimumShouldMatch: '30% ' ),
184+ ['minimum_should_match ' => '30% ' , 'fuzziness ' => '2 ' , 'operator ' => 'or ' ],
185+ ],
186+ ];
187+ }
188+
163189 /**
164190 * @dataProvider provideMultiMatch
165191 */
@@ -190,7 +216,7 @@ public function testWildcard(?WildcardOptions $options, array $expected): void
190216 {
191217 $ dsl = BoolQueryBuilder::make ()->whereWildcard ('foo ' , '%value% ' , $ options )->toDSL ();
192218
193- $ this ->assertArrayFragment (['wildcard ' => ['foo ' => array_merge (['value ' => '%value% ' ], $ expected )]], $ dsl );
219+ $ this ->assertArrayFragment (['must ' => [[ ' wildcard ' => ['foo ' => array_merge (['value ' => '%value% ' ], $ expected )]] ]], $ dsl );
194220 }
195221
196222 public function provideWildcard (): array
@@ -201,4 +227,40 @@ public function provideWildcard(): array
201227 'rewrite options ' => [WildcardOptions::make (rewrite: 'constant_score ' ), ['rewrite ' => 'constant_score ' ]],
202228 ];
203229 }
230+
231+ /**
232+ * @dataProvider provideOrWildcard
233+ */
234+ public function testOrWildcard (?WildcardOptions $ options , array $ expected ): void
235+ {
236+ $ dsl = BoolQueryBuilder::make ()->orWhereWildcard ('foo ' , '%value% ' , $ options )->toDSL ();
237+
238+ $ this ->assertArrayFragment (['should ' => [['wildcard ' => ['foo ' => array_merge (['value ' => '%value% ' ], $ expected )]]]], $ dsl );
239+ }
240+
241+ public function provideOrWildcard (): array
242+ {
243+ return [
244+ 'empty options ' => [WildcardOptions::make (0 , false ), ['boost ' => 0 , 'case_insensitive ' => false ]],
245+ 'full options ' => [WildcardOptions::make (0.5 , true ), ['boost ' => 0.5 , 'case_insensitive ' => true ]],
246+ 'rewrite options ' => [WildcardOptions::make (rewrite: 'constant_score ' ), ['rewrite ' => 'constant_score ' ]],
247+ ];
248+ }
249+
250+ public function testAddMustBool (): void
251+ {
252+ $ builder = BoolQueryBuilder::make ();
253+ $ builder ->where ('mustName ' , 'value ' );
254+ $ builder ->addMustBool (fn (BoolQueryBuilder $ builder ) => $ builder ->orWhereWildcard ('wildcardName ' , 'wildcardValue ' )->orWhereMatch ('matchName ' , 'matchValue ' ));
255+
256+ $ dsl = $ builder ->toDSL ();
257+
258+ $ this ->assertArrayFragment ([
259+ 'filter ' => [["term " => ['mustName ' => 'value ' ]]],
260+ 'must ' => [["bool " => ['should ' => [
261+ ['wildcard ' => ['wildcardName ' => ['value ' => 'wildcardValue ' ]]],
262+ ["match " => ['matchName ' => ['query ' => 'matchValue ' , 'operator ' => 'or ' ]]],
263+ ]]]],
264+ ], $ dsl );
265+ }
204266}
0 commit comments