How can I keep a search index updated with proper data in Laravel, when updating content directly with database?

Viewed 261

I am working on setting up search functionality for nurserypeople.com, and I am using the Directus CMS to manage and update content, while website users will be interacting with the web app that is built on Laravel.

I will be using Laravel Scout for the search index, and Algolia search api I believe. As I will be doing updates through Directus, which does the edits directly on the database and not through Laravel (using the save() method), I am concerned that my search index won't be updated with Laravel Scout as I edit and make changes to content myself.

Is there a way to ensure that content will be properly indexed, like on a weekly/daily basis so I don't have to manually update the index through the command line each time I update content?

Thank you!

1 Answers

Well, I found out the answer to my own question.

In order to update a scout index periodically, you need to add a schedule in App\Commands\Kernel.php, for the command to run daily, weekly, or whenever you want it to run.

For my case. I am going to run scout:import on a weekly basis, which looks like below in the Kernel.

protected function schedule(Schedule $schedule)
{
    $schedule->command('scout:import')->weekly();
}

Hope this helps somebody!

Related