-
Notifications
You must be signed in to change notification settings - Fork 358
Closed
Labels
Description
- Scout Version: 9.4.10
- Scout Driver: MeiliSearch
- Laravel Version: 9.21.6
- PHP Version: 8.1.9
- Database Driver & Version: MySQL 8.0
- SDK Version (If using a third-party service): N/A
- Meilisearch CLI Version (If using Meilisearch): meilisearch-http 0.28.0
Description:
When using custom index keys with getScoutKey() in a Searchable model the MeiliSearchEngine does not correct add the custom key to index nor delete entries from the index.
- The
update()method in the MeiliSearchEngine class uses array_merge() to merge the Scout key index with the toSearchableArray() data but references the Scout key first so the custom key gets overwritten by $searchableData unless a custom key is used.
return array_merge(
// [$model->getKeyName() => $model->getScoutKey()],
$searchableData,
$model->scoutMetadata(),
[$model->getKeyName() => $model->getScoutKey()]
);- RemoveFromSearch job makes a RemoveableScoutCollection which runs the models through
getScoutKey()and passes the result to the thedelete()method in MeiliSearchEngine which then runsgetScountKey()a second time.
ie.
/**
* Remove the given model from the index.
*
* @param \Illuminate\Database\Eloquent\Collection $models
* @return void
*/
public function delete($models)
{
$index = $this->meilisearch->index($models->first()->searchableAs());
$index->deleteDocuments(
// $models->map->getScoutKey()
// ->values()
// ->all()
$models->pluck($models->first()->getKeyName())->toArray()
);
}PS. We may also want to look at replacing getKeyName() with getScoutKeyName() in this MeiliSearchEngine class?
Steps To Reproduce:
- Create a searchable model which overrides the
getScoutKeymethod to prepend a something...
/**
* Get the custom search index key
*
* @return void
*/
public function getScoutKey()
{
return 1 . $this->getKey();
}-
Create and
->save()the model, notice in Meilisearch the ID is not prepended with 1. -
Delete the model, notice the model is not removed from Meilisearch.