Skip to content

Commit 257e58c

Browse files
committed
#96329 Match and multi match filters options
1 parent 310c613 commit 257e58c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/Filtering/AllowedFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static function match(string $name, ?string $field, ?MatchOptions $option
124124
return new static($name, new MatchFilterAction($options ?? new MatchOptions()), $field);
125125
}
126126

127-
public static function multiMatch(string $name, array $fields, ?MultiMatchOptions $options = null): self
127+
public static function multiMatch(string $name, ?array $fields = null, ?MultiMatchOptions $options = null): self
128128
{
129129
return new static(
130130
$name,

src/Filtering/MultiMatchFilterAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function __invoke(BoolQuery $query, mixed $value, string $field): void
2222
->whenMultiple(fn () => throw InvalidQueryException::notSupportMultipleValues($field));
2323
}
2424

25-
public static function encodeFields(array $fields): string
25+
public static function encodeFields(?array $fields): string
2626
{
27-
return implode(',', $fields);
27+
return implode(',', $fields ?: ['*']);
2828
}
2929
}

tests/Integration/FilteringTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,12 @@
115115

116116
searchQuery($spec, ['filter' => ['name' => 'leather']])->assertDocumentOrder([319, 471]);
117117
});
118+
119+
test('multi match filter without fields', function () {
120+
$spec = CompositeSpecification::new()
121+
->allowedFilters([
122+
AllowedFilter::multiMatch('name'),
123+
]);
124+
125+
searchQuery($spec, ['filter' => ['name' => 'leather']])->assertDocumentOrder([319, 471]);
126+
});

0 commit comments

Comments
 (0)