Skip to content

Commit b013a6b

Browse files
committed
V7 add search type and boost
1 parent 2394bff commit b013a6b

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

src/Concerns/InteractsWithIndex.php

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

2222
abstract protected function indexName(): string;
2323

24+
abstract protected function searchType(): ?string;
25+
2426
protected function settings(): array
2527
{
2628
throw new Exception("Need to redefine the method");

src/Contracts/MultiMatchOptions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public static function make(
1414
?string $type = null,
1515
?string $operator = null,
1616
?string $fuzziness = null,
17-
?string $minimumShouldMatch = null
17+
?string $minimumShouldMatch = null,
18+
?float $boost = null
1819
): static {
1920
Assert::nullOrOneOf($type, MatchType::cases());
2021
Assert::nullOrOneOf($operator, ['or', 'and']);
@@ -24,6 +25,7 @@ public static function make(
2425
'operator' => $operator,
2526
'fuzziness' => $fuzziness,
2627
'minimum_should_match' => $minimumShouldMatch,
28+
'boost' => $boost,
2729
]));
2830
}
2931

src/ElasticClient.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ public function getClient(): Client
2222
return $this->client;
2323
}
2424

25-
public function search(string $indexName, array $dsl): array
25+
public function search(string $indexName, array $dsl, ?string $searchType = null): array
2626
{
2727
$this->queryLog?->log($indexName, $dsl);
2828

29-
return $this->client->search([
30-
'index' => $indexName,
31-
'body' => $dsl,
32-
]);
29+
return $this->client
30+
->search(
31+
array_filter([
32+
'index' => $indexName,
33+
'body' => $dsl,
34+
'search_type' => $searchType,
35+
])
36+
);
3337
}
3438

3539
public function searchAsync(string $indexName, array $dsl): FutureArray

src/ElasticIndex.php

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

src/Search/Enums/SearchType.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Ensi\LaravelElasticQuery\Search\Enums;
4+
5+
class SearchType
6+
{
7+
public const QUERY_THEN_FETCH = 'query_then_fetch';
8+
public const DFS_QUERY_THEN_FETCH = 'dfs_query_then_fetch';
9+
10+
public static function cases(): array
11+
{
12+
return [
13+
self::QUERY_THEN_FETCH,
14+
self::DFS_QUERY_THEN_FETCH,
15+
];
16+
}
17+
}

0 commit comments

Comments
 (0)