Skip to content

Commit f67733c

Browse files
authored
Merge pull request #81 from fedorf4/v8-add-unmapped-type-for-sort
v8 Added unmapped_type for sort
2 parents d79cea9 + 8730e29 commit f67733c

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/Concerns/ExtendsSort.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @psalm-require-implements \Ensi\LaravelElasticQuery\Contracts\SortableQuery
1111
*
12-
* @method static sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null)
12+
* @method static sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null, ?string $unmappedType = null)
1313
*/
1414
trait ExtendsSort
1515
{

src/Contracts/SortableQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
interface SortableQuery extends BoolQuery
99
{
10-
public function sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null): static;
10+
public function sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null, ?string $unmappedType = null): static;
1111

1212
public function minSortBy(string $field, string $order = SortOrder::ASC): static;
1313

src/Search/SearchQuery.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ protected function parseHits(array $response): Collection
196196
//endregion
197197

198198
//region Customization
199-
public function sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null): static
199+
public function sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null, ?string $unmappedType = null): static
200200
{
201201
(new SortBuilder($this->sorts))
202-
->sortBy($field, $order, $mode, $missingValues);
202+
->sortBy($field, $order, $mode, $missingValues, $unmappedType);
203203

204204
return $this;
205205
}

src/Search/Sorting/Sort.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function __construct(
1919
private ?string $missingValues = null,
2020
private ?string $type = null,
2121
private ?Script $script = null,
22+
private ?string $unmappedType = null,
2223
) {
2324
Assert::stringNotEmpty(trim($field));
2425
Assert::oneOf($order, SortOrder::cases());
@@ -54,6 +55,10 @@ public function toDSL(): array
5455
$details['script'] = $this->script->toDSL();
5556
}
5657

58+
if ($this->unmappedType !== null) {
59+
$details['unmapped_type'] = $this->unmappedType;
60+
}
61+
5762
if (!$details) {
5863
return [$this->field => $this->order];
5964
}

src/Search/Sorting/SortBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(SortCollection $sorts)
2828
$this->levels = new Collection();
2929
}
3030

31-
public function sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null): static
31+
public function sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null, ?string $unmappedType = null): static
3232
{
3333
$path = $this->absolutePath($field);
3434

@@ -37,7 +37,8 @@ public function sortBy(string $field, string $order = SortOrder::ASC, ?string $m
3737
strtolower($order),
3838
$mode === null ? $mode : strtolower($mode),
3939
$this->buildNested(),
40-
$missingValues
40+
$missingValues,
41+
unmappedType: $unmappedType
4142
);
4243

4344
$this->sorts->add($sort);

0 commit comments

Comments
 (0)