Skip to content

Commit d30e5d7

Browse files
committed
feat: Adds hybrid search options contract for multisearch
1 parent 110be45 commit d30e5d7

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/Contracts/HybridSearchOptions.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MeiliSearch\Contracts;
6+
7+
class HybridSearchOptions
8+
{
9+
private ?float $semanticRatio = null;
10+
private ?string $embedder = null;
11+
12+
public function setSemanticRatio(float $ratio): HybridSearchOptions
13+
{
14+
$this->semanticRatio = $ratio;
15+
16+
return $this;
17+
}
18+
19+
public function setEmbedder(string $embedder): HybridSearchOptions
20+
{
21+
$this->embedder = $embedder;
22+
23+
return $this;
24+
}
25+
26+
public function toArray(): array
27+
{
28+
return array_filter([
29+
'semanticRatio' => $this->semanticRatio,
30+
'embedder' => $this->embedder,
31+
], static function ($item) { return null !== $item; });
32+
}
33+
}

src/Contracts/SearchQuery.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class SearchQuery
2727
private ?int $hitsPerPage;
2828
private ?int $page;
2929
private ?array $vector;
30+
private ?HybridSearchOptions $hybrid;
3031
private ?array $attributesToSearchOn = null;
3132
private ?bool $showRankingScore = null;
3233
private ?bool $showRankingScoreDetails = null;
@@ -237,6 +238,22 @@ public function setVector(array $vector): SearchQuery
237238
return $this;
238239
}
239240

241+
/**
242+
* This is an EXPERIMENTAL feature, which may break without a major version.
243+
*
244+
* Set hybrid search options
245+
* [
246+
* 'semanticRatio'=> 0.8,
247+
* 'embedder' => 'manual',
248+
* ];
249+
*/
250+
public function setHybrid(HybridSearchOptions $hybridOptions): SearchQuery
251+
{
252+
$this->hybrid = $hybridOptions;
253+
254+
return $this;
255+
}
256+
240257
/**
241258
* @param list<non-empty-string> $attributesToSearchOn
242259
*/
@@ -270,6 +287,7 @@ public function toArray(): array
270287
'hitsPerPage' => $this->hitsPerPage ?? null,
271288
'page' => $this->page ?? null,
272289
'vector' => $this->vector ?? null,
290+
'hybrid' => null !== $this->hybrid ? $this->hybrid->toArray() : null,
273291
'attributesToSearchOn' => $this->attributesToSearchOn,
274292
'showRankingScore' => $this->showRankingScore,
275293
'showRankingScoreDetails' => $this->showRankingScoreDetails,

0 commit comments

Comments
 (0)