Skip to content
This repository was archived by the owner on May 13, 2021. It is now read-only.

Commit 74a5d02

Browse files
bors[bot]curquiza
andauthored
Merge #80
80: Fix getTotalCount() method r=curquiza a=curquiza Remove `nbHits` usage because this is not reliable information. The Meili team is aware of this. Here are the different issues and comments about it to explain why it's confusing, and why we should not use it: - meilisearch/meilisearch#1120 - meilisearch/documentation#561 - meilisearch/meilisearch-php#119 (comment) TLDR; `nbHits` is not reliable for pagination because can be exhaustive or not, depending on the value of `exhaustiveNbHits` that MeiliSearch returns which is always `false` for the moment. We are sorry for this. We all hope this confusion will be fixed asap in MeiliSearch. ⚠️ The linter error in the CI will be fixed with #82 Co-authored-by: Clémentine Urquizar <[email protected]>
2 parents 7109189 + a1d4ab3 commit 74a5d02

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Engines/MeilisearchEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function map(Builder $builder, $results, $model)
195195
*/
196196
public function getTotalCount($results)
197197
{
198-
return $results['nbHits'];
198+
return count($results['hits']);
199199
}
200200

201201
/**

tests/MeilisearchEngineTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function mapIdsReturnsEmptyCollectionIfNoHits()
6969
$engine = new MeilisearchEngine($client);
7070

7171
$results = $engine->mapIds([
72-
'nbHits' => 0, 'hits' => [],
72+
'hits' => [],
7373
]);
7474

7575
$this->assertEquals(0, count($results));
@@ -87,7 +87,7 @@ public function mapCorrectlyMapsResultsToModels()
8787
$builder = m::mock(Builder::class);
8888

8989
$results = $engine->map($builder, [
90-
'nbHits' => 1, 'hits' => [
90+
'hits' => [
9191
['id' => 1],
9292
],
9393
], $model);
@@ -113,7 +113,7 @@ public function mapMethodRespectsOrder()
113113
$builder = m::mock(Builder::class);
114114

115115
$results = $engine->map($builder, [
116-
'nbHits' => 4, 'hits' => [
116+
'hits' => [
117117
['id' => 1],
118118
['id' => 2],
119119
['id' => 4],

0 commit comments

Comments
 (0)