Skip to content

Commit b17d623

Browse files
committed
ECS-827
1 parent 0c50845 commit b17d623

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Contracts/DSL.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Ensi\LaravelElasticQuery\Contracts;
4+
5+
use stdClass;
6+
7+
class DSL
8+
{
9+
public static function filter(array $dsl): array|stdClass
10+
{
11+
return array_filter($dsl, fn (mixed $item) => !is_null($item)) ?: new stdClass;
12+
}
13+
}

src/Search/Highlight/Highlight.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Ensi\LaravelElasticQuery\Search\Highlight;
44

5+
use Ensi\LaravelElasticQuery\Contracts\DSL;
56
use Ensi\LaravelElasticQuery\Contracts\DSLAware;
67
use Ensi\LaravelElasticQuery\Filtering\BoolQueryBuilder;
78
use Ensi\LaravelElasticQuery\Search\Enums\BoundaryScanner;
@@ -60,7 +61,7 @@ public function __construct(
6061

6162
public function toDSL(): array|stdClass
6263
{
63-
$dsl = array_filter([
64+
return DSL::filter(array_filter([
6465
'boundary_chars' => $this->boundaryChars,
6566
'boundary_max_scan' => $this->boundaryMaxScan,
6667
'boundary_scanner' => $this->boundaryScanner,
@@ -90,12 +91,6 @@ public function toDSL(): array|stdClass
9091
'max_analyzed_offset' => $this->maxAnalyzedOffset,
9192
'tags_schema' => $this->tagsSchema,
9293
'type' => $this->type,
93-
], fn (mixed $item) => !is_null($item));
94-
95-
if (!$dsl) {
96-
return new stdClass();
97-
}
98-
99-
return $dsl;
94+
]));
10095
}
10196
}

0 commit comments

Comments
 (0)