Skip to content

Commit

Permalink
Merge pull request laravel#372 from Redshift-Web-Design/7.0
Browse files Browse the repository at this point in the history
[7.0] Calling values() on sorted collection to reset the array keys.
  • Loading branch information
taylorotwell authored Apr 19, 2019
2 parents 72d6251 + 3cd8d23 commit 0eb2643
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Engines/AlgoliaEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function map(Builder $builder, $results, $model)
return in_array($model->getScoutKey(), $objectIds);
})->sortBy(function($model) use ($objectIdPositions) {
return $objectIdPositions[$model->getScoutKey()];
});
})->values();
}

/**
Expand Down
10 changes: 9 additions & 1 deletion tests/AlgoliaEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ public function test_map_method_respects_order()
]], $model);

$this->assertEquals(4, count($results));
$this->assertEquals([1, 2, 4, 3], $results->pluck('id')->all());

// It's important we assert with array keys to ensure
// they have been reset after sorting.
$this->assertEquals([
0 => ['id' => 1],
1 => ['id' => 2],
2 => ['id' => 4],
3 => ['id' => 3],
], $results->toArray());
}

public function test_a_model_is_indexed_with_a_custom_algolia_key()
Expand Down

0 comments on commit 0eb2643

Please sign in to comment.