Skip to content

Commit

Permalink
Add support orders, geo_distance
Browse files Browse the repository at this point in the history
  • Loading branch information
ChisThanh committed Oct 23, 2024
1 parent 250ef43 commit 8d07806
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/Domain/Syntax/GeoDistance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace JeroenG\Explorer\Domain\Syntax;

use JeroenG\Explorer\Domain\Syntax\SyntaxInterface;


class GeoDistance implements SyntaxInterface
{

public const DISTANCE_TYPE_ARC = 'arc';
public const DISTANCE_TYPE_PLANE = 'palne';
public const DEFAULT_FIELD = 'location';

private int $distance;
private mixed $lat;
private mixed $lng;
private ?string $distance_type;
private string $field;

public function __construct(
$distance,
$lat,
$lng,
$distance_type = self::DISTANCE_TYPE_ARC,
$field = self::DEFAULT_FIELD,
) {
$this->distance = $distance;
$this->lat = $lat;
$this->lng = $lng;
$this->field = $field;
$this->distance_type = $distance_type;
}

public function build(): array
{
return [
'geo_distance' => [
'distance' => (string) $this->distance,
'distance_type' => (string) $this->distance_type,
$this->field => [
'lat' => (string) $this->lat,
'lon' => (string) $this->lng
]
]
];
}

}
8 changes: 8 additions & 0 deletions src/Infrastructure/Scout/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Builder extends \Laravel\Scout\Builder

public array $fields = [];

public array $orders = [];

public ?BoolQuery $compound = null;

public array $aggregations = [];
Expand All @@ -33,6 +35,12 @@ public function must($must): self
return $this;
}

public function order($order): self
{
$this->orders[] = $order;
return $this;
}

public function should($should): self
{
$this->should[] = $should;
Expand Down

0 comments on commit 8d07806

Please sign in to comment.