Skip to content

Commit c5808fb

Browse files
committed
V8 add search type and boost
1 parent b381cff commit c5808fb

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

src/Concerns/InteractsWithIndex.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ abstract public function tiebreaker(): string;
2020

2121
abstract protected function indexName(): string;
2222

23-
abstract protected function searchType(): ?string;
24-
2523
protected function settings(): array
2624
{
2725
throw new Exception("Need to redefine the method");
@@ -30,9 +28,9 @@ protected function settings(): array
3028
/**
3129
* @see SearchIndex::search()
3230
*/
33-
public function search(array $dsl): array
31+
public function search(array $dsl, ?string $searchType = null): array
3432
{
35-
return $this->resolveClient()->search($this->indexName(), $dsl, $this->searchType());
33+
return $this->resolveClient()->search($this->indexName(), $dsl, $searchType);
3634
}
3735

3836
/**

src/Contracts/MultiMatchOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static function make(
1515
?string $operator = null,
1616
?string $fuzziness = null,
1717
?string $minimumShouldMatch = null,
18-
?float $boost = null
18+
?float $boost = null,
1919
): static {
2020
Assert::nullOrOneOf($type, MatchType::cases());
2121
Assert::nullOrOneOf($operator, ['or', 'and']);

src/Contracts/SearchIndex.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ public function tiebreaker(): string;
1515
* Perform search query.
1616
*
1717
* @param array $dsl
18+
* @param string|null $searchType
1819
* @return array
1920
*/
20-
public function search(array $dsl): array;
21+
public function search(array $dsl, ?string $searchType = null): array;
2122

2223
/**
2324
* Perform delete by query.

src/ElasticIndex.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,4 @@ protected function indexName(): string
2626
{
2727
return $this->name;
2828
}
29-
30-
protected function searchType(): ?string
31-
{
32-
return null;
33-
}
3429
}

src/Search/SearchQuery.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SearchQuery implements SortableQuery, CollapsibleQuery
3535
protected array $fields = [];
3636
protected array $include = [];
3737
protected array $exclude = [];
38+
protected ?string $searchType = null;
3839

3940
public function __construct(protected SearchIndex $index)
4041
{
@@ -150,7 +151,7 @@ protected function execute(
150151
$dsl['search_after'] = $cursor->toDSL();
151152
}
152153

153-
return $this->index->search(array_filter($dsl));
154+
return $this->index->search(array_filter($dsl), $this->searchType);
154155
}
155156

156157
protected function sourceToDSL(bool $source): array | bool
@@ -245,6 +246,15 @@ public function skip(int $count): static
245246
return $this;
246247
}
247248

249+
public function searchType(string $searchType): static
250+
{
251+
Assert::stringNotEmpty($searchType);
252+
253+
$this->searchType = $searchType;
254+
255+
return $this;
256+
}
257+
248258
//endregion
249259

250260
protected function boolQuery(): BoolQueryBuilder

0 commit comments

Comments
 (0)