Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds hybrid search options contract for multisearch #670

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Contracts/HybridSearchOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace MeiliSearch\Contracts;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
namespace MeiliSearch\Contracts;
namespace Meilisearch\Contracts;


class HybridSearchOptions
{
private ?float $semanticRatio = null;
private ?string $embedder = null;
Copy link
Collaborator

@norkunas norkunas Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private ?string $embedder = null;
/**
* @var non-empty-string|null
*/
private ?string $embedder = null;


public function setSemanticRatio(float $ratio): HybridSearchOptions
{
$this->semanticRatio = $ratio;

return $this;
}

public function setEmbedder(string $embedder): HybridSearchOptions
apozeus marked this conversation as resolved.
Show resolved Hide resolved
{
$this->embedder = $embedder;

return $this;
}

Copy link
Collaborator

@norkunas norkunas Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* @return array{
* semanticRatio?: float,
* embedder?: non-empty-string
* }
*/

public function toArray(): array
{
return array_filter([
'semanticRatio' => $this->semanticRatio,
'embedder' => $this->embedder,
], static function ($item) { return null !== $item; });
}
}
18 changes: 18 additions & 0 deletions src/Contracts/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
private ?int $hitsPerPage;
private ?int $page;
private ?array $vector;
private ?HybridSearchOptions $hybrid;

Check failure on line 30 in src/Contracts/SearchQuery.php

View workflow job for this annotation

GitHub Actions / phpstan-tests

Class MeiliSearch\Contracts\HybridSearchOptions referenced with incorrect case: Meilisearch\Contracts\HybridSearchOptions.

Check failure on line 30 in src/Contracts/SearchQuery.php

View workflow job for this annotation

GitHub Actions / phpstan-tests

Class MeiliSearch\Contracts\HybridSearchOptions referenced with incorrect case: Meilisearch\Contracts\HybridSearchOptions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private ?HybridSearchOptions $hybrid;
private ?HybridSearchOptions $hybrid = null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing it now too. and have made a similar commit. please check.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've commited it to another PR. so please choose one and close another one.

private ?array $attributesToSearchOn = null;
private ?bool $showRankingScore = null;
private ?bool $showRankingScoreDetails = null;
Expand Down Expand Up @@ -237,6 +238,22 @@
return $this;
}

/**
* This is an EXPERIMENTAL feature, which may break without a major version.
*
* Set hybrid search options
* [
* 'semanticRatio'=> 0.8,
* 'embedder' => 'manual',
* ];
apozeus marked this conversation as resolved.
Show resolved Hide resolved
*/
public function setHybrid(HybridSearchOptions $hybridOptions): SearchQuery

Check failure on line 250 in src/Contracts/SearchQuery.php

View workflow job for this annotation

GitHub Actions / phpstan-tests

Class MeiliSearch\Contracts\HybridSearchOptions referenced with incorrect case: Meilisearch\Contracts\HybridSearchOptions.

Check failure on line 250 in src/Contracts/SearchQuery.php

View workflow job for this annotation

GitHub Actions / phpstan-tests

Class MeiliSearch\Contracts\HybridSearchOptions referenced with incorrect case: Meilisearch\Contracts\HybridSearchOptions.
{
$this->hybrid = $hybridOptions;

return $this;
}

/**
* @param list<non-empty-string> $attributesToSearchOn
*/
Expand Down Expand Up @@ -270,6 +287,7 @@
'hitsPerPage' => $this->hitsPerPage ?? null,
'page' => $this->page ?? null,
'vector' => $this->vector ?? null,
'hybrid' => null !== $this->hybrid ? $this->hybrid->toArray() : null,
'attributesToSearchOn' => $this->attributesToSearchOn,
'showRankingScore' => $this->showRankingScore,
'showRankingScoreDetails' => $this->showRankingScoreDetails,
Expand Down
Loading