Skip to content

Commit

Permalink
Merge branch 'main' into meili-bot/bump-version
Browse files Browse the repository at this point in the history
  • Loading branch information
curquiza authored Dec 12, 2024
2 parents 3d128eb + 20f68c7 commit aa06a3d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"php-cs-fixer/shim": "^3.59.3",
"guzzlehttp/guzzle": "^7.8.1",
"http-interop/http-factory-guzzle": "^1.2.0",
"phpstan/phpstan": "^1.11.5",
"phpstan/phpstan": "^2.0",
"phpstan/extension-installer": "^1.4.1",
"phpstan/phpstan-strict-rules": "^1.6.0",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-deprecation-rules": "^1.2.0"
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-deprecation-rules": "^2.0"
},
"scripts": {
"lint": [
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function __construct(
$this->http = $httpClient ?? Psr18ClientDiscovery::find();
$this->requestFactory = $reqFactory ?? Psr17FactoryDiscovery::findRequestFactory();
$this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory();
$this->headers = array_filter([
$this->headers = [
'User-Agent' => implode(';', array_merge($clientAgents, [Meilisearch::qualifiedVersion()])),
]);
];
if (null !== $apiKey && '' !== $apiKey) {
$this->headers['Authorization'] = \sprintf('Bearer %s', $apiKey);
}
Expand Down
24 changes: 12 additions & 12 deletions src/Search/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ class SearchResult implements \Countable, \IteratorAggregate
* and its value will not be modified by the methods in this class.
* Please, use `hitsCount` if you want to know the real size of the `hits` array at any time.
*/
private ?int $estimatedTotalHits;
private ?int $hitsCount;
private ?int $offset;
private ?int $limit;
private ?int $semanticHitCount;
private ?int $estimatedTotalHits = null;
private int $hitsCount;
private ?int $offset = null;
private ?int $limit = null;
private int $semanticHitCount;

private ?int $hitsPerPage;
private ?int $page;
private ?int $totalPages;
private ?int $totalHits;
private ?int $hitsPerPage = null;
private ?int $page = null;
private ?int $totalPages = null;
private ?int $totalHits = null;

private int $processingTimeMs;
private bool $numberedPagination;
Expand Down Expand Up @@ -126,12 +126,12 @@ public function getHits(): array
return $this->hits;
}

public function getOffset(): int
public function getOffset(): ?int
{
return $this->offset;
}

public function getLimit(): int
public function getLimit(): ?int
{
return $this->limit;
}
Expand All @@ -154,7 +154,7 @@ public function count(): int
return $this->hitsCount;
}

public function getEstimatedTotalHits(): int
public function getEstimatedTotalHits(): ?int
{
return $this->estimatedTotalHits;
}
Expand Down
19 changes: 18 additions & 1 deletion tests/Endpoints/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ public function testBasicSearch(): void
$response = $this->index->search('prince');

$this->assertEstimatedPagination($response->toArray());
self::assertSame(2, $response->getEstimatedTotalHits());
self::assertCount(2, $response->getHits());

self::assertSame(2, $response->getEstimatedTotalHits());
self::assertSame(0, $response->getOffset());
self::assertSame(20, $response->getLimit());

self::assertNull($response->getHitsPerPage());
self::assertNull($response->getPage());
self::assertNull($response->getTotalPages());
self::assertNull($response->getTotalHits());

$response = $this->index->search('prince', [], [
'raw' => true,
]);
Expand All @@ -44,6 +52,15 @@ public function testBasicSearchWithFinitePagination(): void
$this->assertFinitePagination($response->toArray());
self::assertCount(2, $response->getHits());

self::assertSame(2, $response->getHitsPerPage());
self::assertSame(1, $response->getPage());
self::assertSame(1, $response->getTotalPages());
self::assertSame(2, $response->getTotalHits());

self::assertNull($response->getEstimatedTotalHits());
self::assertNull($response->getOffset());
self::assertNull($response->getLimit());

$response = $this->index->search('prince', ['hitsPerPage' => 2], [
'raw' => true,
]);
Expand Down

0 comments on commit aa06a3d

Please sign in to comment.