-
Notifications
You must be signed in to change notification settings - Fork 358
[9.x] Fix custom scout keys not being utilized when deleting from queue #656
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
Merged
taylorotwell
merged 16 commits into
laravel:9.x
from
stevebauman:fix-removeable-scout-collection-with-custom-key
Oct 4, 2022
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1959292
Add getUnqualifiedScoutKeyName method
stevebauman 6146bb7
Add RemoveableScoutCollection tests
stevebauman 071c9de
Change order of update indexing so a custom key cannot be overridden …
stevebauman d996a04
Return a RemoveableScoutCollection instance and fix key type when sco…
stevebauman 73227bb
Add `RemoveFromSearch` meilisearch tests
stevebauman aba8564
Flush the container on tear down
stevebauman 7bea1cc
Remove unneeded tearDown
stevebauman 625ba1b
Update algolia engine to delete using custom keys
stevebauman 745ce0b
Add Algolia deletion tests with custom keys
stevebauman ce381f9
Rename "$values" to "$keys" for clarity
stevebauman 8b9270f
Spacing
stevebauman e137aa4
Remove unused imports
stevebauman d3557d2
CS fixes
stevebauman 1934e76
Comment clarification
stevebauman 3fdb281
Move scout key array merge priority
stevebauman 1d6a576
Update RemoveFromSearch.php
taylorotwell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@stevebauman - PS. If people are already adding the key in their toSearchableArray() with some value other than what's returned from
getScoutKey(). Worth considering perhaps? Might also then want to make this change in the MeiliSearchEngine to ensure theobjectIDkey is not overridden?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 is also something that jumped to my eye. The order here was definitly on purpose the way it was before. is there a specific reason why this was change?
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.
@stevebauman can you maybe answer this question?
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry for the late reply on this one guys! I modified this due to conflicts with the searchable data array. The priority here was intended.
$searchableDatawill contain the model's attributes, including its primary key, alongside other data:This means, the custom Scout key will always be overridden (unless the model uses a different primary key).
Without this, the
array_merge()structure would be:Leading to the custom scout key always being overridden by the primary key.
I'm not really sure how we can account for that due to the above scenario... The primary key will likely always be present, so the custom Scout key will never be included in the indexed data. Correct me if I'm wrong?
Don't you specify the primary key with the MeilisearchEngine? I can't find any reference to objectID inside of Meilisearch's documentation.
Uh oh!
There was an error while loading. Please reload this page.
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.
The implementations the above
array_merge()priority for theMeiliSearchEngineandAlgoliaEnginediffer, asAlgoliarequires a primary key ofobjectID. You cannot change it (to my knowledge). WhileMeiliSearchallows you to change it:scout/src/Engines/AlgoliaEngine.php
Lines 65 to 69 in 3352fbc
Since
objectIDis unlikely to be a models primary key, collisions in thearray_merge()are unlikely, so I haven't adjusted it. Maybe we should to ensure the same "priority" consistency across the included engines?AlgoliaEngine:
scout/src/Engines/AlgoliaEngine.php
Line 194 in 3352fbc
MeiliSearchEngine:
scout/src/Engines/MeiliSearchEngine.php
Line 266 in 3352fbc
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.
@stevebauman - You're correct, the array_merge() must decide if it wants to override the
toSearchableArray()or use the value from there if the user has specified the key returned bygetScoutKeyName().I am in favor of your method change which will override
toSearchableArray()as this will ensure the rest of the functionality will operate on the correct ID giving the user some protection against bad configurations? Either way it might be worth a mention somewhere in the docs if it's not there already?@stevebauman - Sorry noticed a typo in my previous suggestion, I meant to make the change in the AlgoliaEngine to be sure that the user can't override the
objectIDkey in thetoSearchableArray()but can only modify the value withgetScoutKey()as intended.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.
No worries! Understood, I agree with this change. I've moved the order of this in the
AlgoliaEngineas well. 👍