laravel / scout

Laravel Scout provides a driver based solution to searching your Eloquent models.
https://laravel.com/docs/scout
MIT License
1.54k stars 327 forks source link

Add Index Events & fix unnecessary Typesense Index Creation on Flush #828

Closed stammbach closed 4 months ago

stammbach commented 4 months ago

Changes:

Currently there is no easy way to utilise Index/Collection based features like Synonyms provided by Meilisearch or Typesense. With the newly added events you can directly hook into after the creation and register them for example.

Example Usage:


Event::listen(IndexCreated::class, function (IndexCreated $event) {
    $index = $event->index;

    logger('Created Index', ['index' => $index]);

    $typesense = app(EngineManager::class)->engine();

    $collection = $typesense->getCollections()->{$index};

    $synonyms = $collection->getSynonyms();

    $synonym = $synonyms->upsert('coat-synonyms', [
        'synonyms' => [
            'blazer', 'coat', 'jacket'
        ],
    ]);

    logger('Created Synonym', $synonym);
});

Event::listen(IndexDeleted::class, function (IndexDeleted $event) {
    $index = $event->index;

    logger('Deleted Index', ['index' => $index]);
});
driesvints commented 4 months ago

@karakhanyans does this look good to you?

taylorotwell commented 4 months ago

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

stammbach commented 4 months ago

Hey @taylorotwell I understand that you maintain many repositories, hence the copy paste message. But I'm curious what's the reason for not accepting?