-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.x] Return correct output of mapIds method for MeiliSearch #538
[9.x] Return correct output of mapIds method for MeiliSearch #538
Conversation
Can you try to explain again why the current code is broken with examples? I'm not following. |
@taylorotwell so if the result of the meilisearch payload is not ordered with the primary field first, then the ids are selected from the first element of each item. See this: |
But that's not what the existing code is depending on - I don't see anywhere in the current code where we expect the |
Nevermind I see where you are talking about. |
When doing a search with |
Honestly I suggest trying to fix this without a breaking change - even if you have to introduce a new method on the MeiliSearch engine like |
@taylorotwell I updated the code Rebase to 9.x? |
/** | ||
* Pluck and return the primary keys of the given results. | ||
* This expects the first item of each search item array to be the primary key. | ||
* Use mapIdsFrom() instead to get the correct results based on a given primary key. | ||
* | ||
* @param mixed $results | ||
* @return \Illuminate\Support\Collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've let the mapIds()
method untouched so others get the same result back if they were depending on it, even tough it doesnt return the results they actually would expect
@mmachatschek if there's no breaking changes left then yes we should target 9.x, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@driesvints I rebased the PR
@@ -5,6 +5,7 @@ | |||
use Illuminate\Container\Container; | |||
use Illuminate\Pagination\LengthAwarePaginator; | |||
use Illuminate\Pagination\Paginator; | |||
use Illuminate\Support\Str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be removed in 10.x
src/Builder.php
Outdated
@@ -434,7 +435,7 @@ protected function getTotalCount($results) | |||
return $totalCount; | |||
} | |||
|
|||
$ids = $engine->mapIds($results)->all(); | |||
$ids = $engine->mapIdsFrom($results, Str::afterLast($this->model->getScoutKeyName(), '.'))->all(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@driesvints this needs to be changed to this on the master branch where we don't need the getScoutKeyName fix
$ids = $engine->mapIdsFrom($results, Str::afterLast($this->model->getScoutKeyName(), '.'))->all(); | |
$ids = $engine->mapIdsFrom($results, $this->model->getScoutKeyName())->all(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this is merged, I'll merge it into master. Can you send in a PR after that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
I had the same issue. keys() method does not work correctly. "laravel/framework": "^8.54", |
This fixes issue #535
The problem with the meilisearch engine in this context is that when calling the
mapIds()
method on the engine, it tries to pluck all primary keys of the results. For MeiliSearch this key is customizable so we can not guess the primary key.The inital implementation just returned the values of the first entry of the result array.
Algolia doesn't have this problem as it always uses
objectID
as the primary key.This is a breaking change because we need to pass the model to the
mapIds()
method in order to correctly pluck the primary key from the results.