Sti3bas / laravel-scout-array-driver

Array driver for Laravel Scout
MIT License
89 stars 8 forks source link

Remove search callback call #15

Closed cbaconnier closed 1 year ago

cbaconnier commented 1 year ago

Fix the issue https://github.com/Sti3bas/laravel-scout-array-driver/issues/14

I'm still not sure why we need this. But this is currently broken when we use a callback as the method does not uses the same arguments and would need to add, at least, the search method in the store since it's being called in the callback (and potentially others methods given to the users by Algolia|Meilisearch clients).

Exemple of callback

 // Currently, when running tests, $meilisearch is an instance of ArrayStore
App\Models\User::search('John Doe', function($meilisearch, string $query, array $options) {
    $options['sort'] = ['name:asc'];
    $options['filter'] = 'email IS NOT NULL';

    /** @var Meilisearch\Endpoints\Indexes $meilisearch */
    return $meilisearch->search($query, $options);
})->get();

See https://github.com/cbaconnier/laravel-scout-array-bug/commit/cdb3620abe1696497cc6cbdb702d64f2dffa4970

~I also mentioned in the issue, as alternative, we could store the callback(s) to allow the users to tests them separately.~

Search::assertSearchedWithCallback(function(Indexes $meiliSearch, string $query, array $options){
    return true;
}); 

But I haven't got the time to investigate how to adapt the Store for this. What do you think?

Edit: I don't think we can't add assertSearchedWithCallback test since we cannot compare closure. Or at least I have no knowledge of it.

Sti3bas commented 1 year ago

@cbaconnier I will merge this in as a temporary solution until I will release the changes mentioned here.