Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Concerns/ExtendsSort.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @psalm-require-implements \Ensi\LaravelElasticQuery\Contracts\SortableQuery
*
* @method static sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null)
* @method static sortBy(string $field, string $order = SortOrder::ASC, ?string $mode = null, ?string $missingValues = null, ?string $unmappedType = null)
*/
trait ExtendsSort
{
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/SortableQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/Search/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ protected function parseHits(array $response): Collection
//endregion

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

return $this;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Search/Sorting/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(
private ?string $missingValues = null,
private ?string $type = null,
private ?Script $script = null,
private ?string $unmappedType = null,
) {
Assert::stringNotEmpty(trim($field));
Assert::oneOf($order, SortOrder::cases());
Expand Down Expand Up @@ -54,6 +55,10 @@ public function toDSL(): array
$details['script'] = $this->script->toDSL();
}

if ($this->unmappedType !== null) {
$details['unmapped_type'] = $this->unmappedType;
}

if (!$details) {
return [$this->field => $this->order];
}
Expand Down
5 changes: 3 additions & 2 deletions src/Search/Sorting/SortBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(SortCollection $sorts)
$this->levels = new Collection();
}

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

Expand All @@ -37,7 +37,8 @@ public function sortBy(string $field, string $order = SortOrder::ASC, ?string $m
strtolower($order),
$mode === null ? $mode : strtolower($mode),
$this->buildNested(),
$missingValues
$missingValues,
unmappedType: $unmappedType
);

$this->sorts->add($sort);
Expand Down