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

Changes related to the next Meilisearch release (v1.3.0) #539

Merged
merged 22 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9f07bd9
Update README.md
meili-bot Jul 5, 2023
7551761
Add tests to ensure support to the vector store
brunoocasali Jul 10, 2023
b3a89aa
Add vector to SearchQuery
brunoocasali Jul 10, 2023
aa5dc60
Update src/Contracts/SearchQuery.php
brunoocasali Jul 11, 2023
434f482
Update src/Contracts/SearchQuery.php
brunoocasali Jul 11, 2023
6a38fe6
Add _semanticScore key in the tests
brunoocasali Jul 11, 2023
945a2af
Add support to attributesToSearchOn
brunoocasali Jul 10, 2023
779d520
Update src/Contracts/SearchQuery.php
brunoocasali Jul 11, 2023
af77341
Set attributesToSearchOn as null
brunoocasali Jul 11, 2023
76fc37c
Ensure showRankingScore is supported
brunoocasali Jul 10, 2023
da5fc60
Make the $showRankingScore attribute null by default
brunoocasali Jul 11, 2023
084a174
Add experimental feature `setShowRankingScoreDetails`
brunoocasali Jul 10, 2023
f11dcff
Add showRankingScoreDetails to toArray() definition
brunoocasali Jul 11, 2023
ef948fe
Add faceting settings
brunoocasali Jul 11, 2023
b6bd6b5
Add facetSearch function to Indexes
brunoocasali Jul 12, 2023
da2dac8
Add getTotal() in the TasksResults type
brunoocasali Jul 12, 2023
3c08dfd
Merge pull request #549 from meilisearch/faceting-config
brunoocasali Jul 24, 2023
a8f909a
Merge pull request #550 from meilisearch/search-on-facets
brunoocasali Jul 27, 2023
e792081
Update TasksResults.php
brunoocasali Jul 27, 2023
700f747
Merge pull request #551 from meilisearch/task-results
brunoocasali Jul 27, 2023
56bfc56
Update typehint
brunoocasali Jul 27, 2023
49e2094
Merge branch 'main' into bump-meilisearch-v1.3.0
brunoocasali Jul 27, 2023
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
57 changes: 57 additions & 0 deletions src/Contracts/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class SearchQuery
private ?int $limit;
private ?int $hitsPerPage;
private ?int $page;
private ?array $vector;
private ?array $attributesToSearchOn = null;
private ?bool $showRankingScore = null;
private ?bool $showRankingScoreDetails = null;

public function setQuery(string $q): SearchQuery
{
Expand Down Expand Up @@ -103,6 +107,29 @@ public function setShowMatchesPosition(?bool $showMatchesPosition): SearchQuery
return $this;
}

public function setShowRankingScore(?bool $showRankingScore): SearchQuery
{
$this->showRankingScore = $showRankingScore;

return $this;
}

/**
* This is an EXPERIMENTAL feature, which may break without a major version.
* It's available after Meilisearch v1.3.
* To enable it properly and use ranking scoring details its required to opt-in through the /experimental-features route.
*
* More info: https://www.meilisearch.com/docs/reference/api/experimental-features
*
* @param bool $showRankingScoreDetails whether the feature is enabled or not
*/
public function setShowRankingScoreDetails(?bool $showRankingScoreDetails): SearchQuery
{
$this->showRankingScoreDetails = $showRankingScoreDetails;

return $this;
}

public function setSort(array $sort): SearchQuery
{
$this->sort = $sort;
Expand Down Expand Up @@ -152,6 +179,32 @@ public function setIndexUid(string $uid): SearchQuery
return $this;
}

/**
* This is an EXPERIMENTAL feature, which may break without a major version.
* It's available from Meilisearch v1.3.
* To enable it properly and use vector store capabilities it's required to activate it through the /experimental-features route.
*
* More info: https://www.meilisearch.com/docs/reference/api/experimental-features
*
* @param array<float> $vector a multi-level array floats
brunoocasali marked this conversation as resolved.
Show resolved Hide resolved
*/
public function setVector(array $vector): SearchQuery
{
$this->vector = $vector;

return $this;
}

/**
* @param list<non-empty-string> $attributesToSearchOn
*/
public function setAttributesToSearchOn(array $attributesToSearchOn): SearchQuery
{
$this->attributesToSearchOn = $attributesToSearchOn;

return $this;
}

public function toArray(): array
{
return array_filter([
Expand All @@ -173,6 +226,10 @@ public function toArray(): array
'limit' => $this->limit ?? null,
'hitsPerPage' => $this->hitsPerPage ?? null,
'page' => $this->page ?? null,
'vector' => $this->vector ?? null,
'attributesToSearchOn' => $this->attributesToSearchOn,
'showRankingScore' => $this->showRankingScore,
'showRankingScoreDetails' => $this->showRankingScoreDetails,
], function ($item) { return null !== $item; });
}
}
7 changes: 6 additions & 1 deletion tests/Endpoints/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public function testIndexGetSettings(): void
);
$this->assertSame([], $this->index->getFilterableAttributes());
$this->assertSame(['*'], $this->index->getDisplayedAttributes());
$this->assertSame(['maxValuesPerFacet' => 100], $this->index->getFaceting());
$this->assertSame([
'maxValuesPerFacet' => 100,
'sortFacetValuesBy' => [
'*' => 'alpha',
],
], $this->index->getFaceting());
$this->assertSame(['maxTotalHits' => 1000], $this->index->getPagination());
$this->assertSame(
[
Expand Down
17 changes: 17 additions & 0 deletions tests/Endpoints/MultiSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,21 @@ public function testMultiSearch(): void
$this->assertArrayHasKey('totalPages', $response['results'][1]);
$this->assertCount(1, $response['results'][1]['hits']);
}

public function testSupportedQueryParams(): void
{
$query = (new SearchQuery())
->setIndexUid($this->booksIndex->getUid())
->setVector([1, 0.9, [0.9874]])
->setAttributesToSearchOn(['comment'])
->setShowRankingScore(true)
->setShowRankingScoreDetails(true);

$result = $query->toArray();

$this->assertEquals([1, 0.9, [0.9874]], $result['vector']);
$this->assertEquals(['comment'], $result['attributesToSearchOn']);
$this->assertEquals(true, $result['showRankingScore']);
$this->assertEquals(true, $result['showRankingScoreDetails']);
}
}
48 changes: 48 additions & 0 deletions tests/Endpoints/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Meilisearch\Endpoints\Indexes;
use Meilisearch\Exceptions\ApiException;
use Meilisearch\Http\Client;
use Tests\TestCase;

final class SearchTest extends TestCase
Expand Down Expand Up @@ -687,6 +688,36 @@ public function testBasicSearchWithFacetsOptionAndMultipleFacets(): void
$this->assertEquals($response->getRaw()['facetDistribution'], $response->getFacetDistribution());
}

public function testVectorSearch(): void
{
$http = new Client($this->host, getenv('MEILISEARCH_API_KEY'));
$http->patch('/experimental-features', ['vectorStore' => true]);

$response = $this->index->addDocuments([
['id' => 32, 'title' => 'The Witcher', '_vectors' => [1, 0.3]],
['id' => 32, 'title' => 'Interestellar', '_vectors' => [0.5, 0.53]],
]);
$this->index->waitForTask($response['taskUid']);

$response = $this->index->search('', ['vector' => [0.5921]]);
$hit = $response->getHits()[0];

$this->assertEquals($hit['title'], 'Interestellar');
$this->assertEquals($hit['_vectors'], [0.5, 0.53]);
$this->assertArrayHasKey('_semanticScore', $hit);
}

public function testShowRankingScoreDetails(): void
{
$http = new Client($this->host, getenv('MEILISEARCH_API_KEY'));
$http->patch('/experimental-features', ['scoreDetails' => true]);

$response = $this->index->search('the', ['showRankingScoreDetails' => true]);
$hit = $response->getHits()[0];

$this->assertArrayHasKey('_rankingScoreDetails', $hit);
}

public function testBasicSearchWithTransformFacetsDritributionOptionToFilter(): void
{
$response = $this->index->updateFilterableAttributes(['genre']);
Expand Down Expand Up @@ -719,6 +750,23 @@ function (int $facetValue): bool { return 1 < $facetValue; },
$this->assertEquals(2, $response->getFacetDistribution()['genre']['fantasy']);
}

public function testSearchWithAttributesToSearchOn(): void
{
$response = $this->index->updateSearchableAttributes(['comment', 'title']);
$this->index->waitForTask($response['taskUid']);

$response = $this->index->search('the', ['attributesToSearchOn' => ['comment']]);

$this->assertEquals('The best book', $response->getHits()[0]['comment']);
}

public function testSearchWithShowRankingScore(): void
{
$response = $this->index->search('the', ['showRankingScore' => true]);

$this->assertArrayHasKey('_rankingScore', $response->getHits()[0]);
}

public function testBasicSearchWithTransformFacetsDritributionOptionToMap(): void
{
$response = $this->index->updateFilterableAttributes(['genre']);
Expand Down