Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gazzoy committed Dec 26, 2023
1 parent c49d598 commit 382ea84
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
52 changes: 30 additions & 22 deletions src/Engines/OpenSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ public function __call($method, $parameters)
return $this->client->{$method}(...$parameters);
}

/**
* Get options.
*
* @param array<string, mixed> $options
*
* @return array<string, mixed>
*/
private function getOptions(Builder $builder, array $options): array
{
if (property_exists($builder, 'distinctField') && filled($builder->distinctField)) {
Expand All @@ -372,12 +379,17 @@ private function getOptions(Builder $builder, array $options): array
return $options;
}

/**
* Filter query.
*
* @return array<string, mixed>
*/
private function filters(Builder $builder): array
{
$query = [];

if ($builder->query !== '' && $builder->query !== '0') {
/** @phpstan-ignore-line */
/** @phpstan-ignore-next-line */
$fields = $builder->model->searchableFields();

$query['bool'] = [
Expand All @@ -393,29 +405,25 @@ private function filters(Builder $builder): array
];
}

if (\count($builder->wheres) > 0) {
$wheres = array_merge([
'__soft_deleted' => 0,
], $builder->wheres);

foreach ($wheres as $key => $value) {
if (\is_array($value) && isset($value['SCOUT_OPENSEARCH_OP_RANGE'])) {
$range = $value['SCOUT_OPENSEARCH_OP_RANGE'];
$query['bool']['filter'][] = [
'range' => [
$key => $range,
],
];
} else {
$query['bool']['filter'][] = [
'term' => [
$key => $value,
],
];
}
$wheres = array_merge([
'__soft_deleted' => 0,
], $builder->wheres);
foreach ($wheres as $key => $value) {
if (\is_array($value) && isset($value['SCOUT_OPENSEARCH_OP_RANGE'])) {
$range = $value['SCOUT_OPENSEARCH_OP_RANGE'];
$query['bool']['filter'][] = [
'range' => [
$key => $range,
],
];
} else {
$query['bool']['filter'][] = [
'term' => [
$key => $value,
],
];
}
}
// end if

if (\count($builder->whereIns) > 0) {
$query['bool']['minimum_should_match'] = \count($builder->whereIns);
Expand Down
7 changes: 6 additions & 1 deletion src/OpenSearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

class OpenSearchServiceProvider extends ServiceProvider
{
protected $wheres = [];
/**
* where conditions.
*
* @var array<int|string, mixed>
*/
protected array $wheres = [];

protected ?string $distinctField = null;

Expand Down

0 comments on commit 382ea84

Please sign in to comment.