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

Commit

Permalink
Merge #80
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and curquiza authored Jan 27, 2021
2 parents 7109189 + a1d4ab3 commit 74a5d02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function map(Builder $builder, $results, $model)
*/
public function getTotalCount($results)
{
return $results['nbHits'];
return count($results['hits']);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/MeilisearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function mapIdsReturnsEmptyCollectionIfNoHits()
$engine = new MeilisearchEngine($client);

$results = $engine->mapIds([
'nbHits' => 0, 'hits' => [],
'hits' => [],
]);

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

$results = $engine->map($builder, [
'nbHits' => 1, 'hits' => [
'hits' => [
['id' => 1],
],
], $model);
Expand All @@ -113,7 +113,7 @@ public function mapMethodRespectsOrder()
$builder = m::mock(Builder::class);

$results = $engine->map($builder, [
'nbHits' => 4, 'hits' => [
'hits' => [
['id' => 1],
['id' => 2],
['id' => 4],
Expand Down

0 comments on commit 74a5d02

Please sign in to comment.