-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
539: Changes related to the next Meilisearch release (v1.3.0) r=brunoocasali a=meili-bot Related to this issue: meilisearch/integration-guides#280 This PR: - gathers the changes related to the next Meilisearch release (v1.3.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v1.3.0 is out.⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.3.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Bruno Casali <[email protected]>
- Loading branch information
Showing
14 changed files
with
399 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Meilisearch\Contracts; | ||
|
||
class FacetSearchQuery | ||
{ | ||
private ?string $q = null; | ||
private ?string $matchingStrategy = null; | ||
private ?array $filter = null; | ||
private ?string $facetQuery = null; | ||
private ?string $facetName = null; | ||
|
||
public function setQuery(string $q): FacetSearchQuery | ||
{ | ||
$this->q = $q; | ||
|
||
return $this; | ||
} | ||
|
||
public function setMatchingStrategy(string $matchingStrategy): FacetSearchQuery | ||
{ | ||
$this->matchingStrategy = $matchingStrategy; | ||
|
||
return $this; | ||
} | ||
|
||
public function setFilter(array $filter): FacetSearchQuery | ||
{ | ||
$this->filter = $filter; | ||
|
||
return $this; | ||
} | ||
|
||
public function setFacetQuery(string $facetQuery): FacetSearchQuery | ||
{ | ||
$this->facetQuery = $facetQuery; | ||
|
||
return $this; | ||
} | ||
|
||
public function setFacetName(string $facetName): FacetSearchQuery | ||
{ | ||
$this->facetName = $facetName; | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'q' => $this->q, | ||
'matchingStrategy' => $this->matchingStrategy, | ||
'filter' => $this->filter, | ||
'facetQuery' => $this->facetQuery, | ||
'facetName' => $this->facetName, | ||
], function ($item) { return null !== $item; }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Meilisearch\Contracts\Index; | ||
|
||
use Meilisearch\Contracts\Data; | ||
|
||
class Faceting extends Data implements \JsonSerializable | ||
{ | ||
public function jsonSerialize(): object | ||
{ | ||
return (object) $this->getIterator()->getArrayCopy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Meilisearch\Search; | ||
|
||
class FacetSearchResult implements \Countable, \IteratorAggregate | ||
{ | ||
/** | ||
* @var array<int, array<string, mixed>> | ||
*/ | ||
private array $facetHits; | ||
private int $processingTimeMs; | ||
private ?string $facetQuery; | ||
|
||
public function __construct(array $body) | ||
{ | ||
$this->facetHits = $body['facetHits'] ?? []; | ||
$this->facetQuery = $body['facetQuery']; | ||
$this->processingTimeMs = $body['processingTimeMs']; | ||
} | ||
|
||
/** | ||
* @return array<int, array> | ||
*/ | ||
public function getFacetHits(): array | ||
{ | ||
return $this->facetHits; | ||
} | ||
|
||
public function getProcessingTimeMs(): int | ||
{ | ||
return $this->processingTimeMs; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'facetHits' => $this->facetHits, | ||
'facetQuery' => $this->facetQuery, | ||
'processingTimeMs' => $this->processingTimeMs, | ||
]; | ||
} | ||
|
||
public function toJSON(): string | ||
{ | ||
return json_encode($this->toArray(), JSON_PRETTY_PRINT); | ||
} | ||
|
||
public function getIterator(): \ArrayIterator | ||
{ | ||
return new \ArrayIterator($this->facetHits); | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return \count($this->facetHits); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Endpoints; | ||
|
||
use Meilisearch\Contracts\FacetSearchQuery; | ||
use Meilisearch\Endpoints\Indexes; | ||
use Tests\TestCase; | ||
|
||
final class FacetSearchTest extends TestCase | ||
{ | ||
private Indexes $index; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->index = $this->createEmptyIndex($this->safeIndexName()); | ||
$this->index->updateDocuments(self::DOCUMENTS); | ||
$promise = $this->index->updateFilterableAttributes(['genre']); | ||
$this->index->waitForTask($promise['taskUid']); | ||
} | ||
|
||
public function testBasicSearchWithFilters(): void | ||
{ | ||
$response = $this->index->search('prince', ['facets' => ['genre']]); | ||
|
||
$this->assertSame(array_keys($response->getFacetDistribution()['genre']), [ | ||
'adventure', 'fantasy', | ||
]); | ||
|
||
$response = $this->index->facetSearch( | ||
(new FacetSearchQuery()) | ||
->setFacetQuery('fa') | ||
->setFacetName('genre') | ||
->setQuery('prince') | ||
); | ||
|
||
$this->assertSame(array_column($response->getFacetHits(), 'value'), ['fantasy']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.