This Laravel package allows for batching of Scout updates.

Overview

Laravel Scout Batch Searchable

Latest Version on Packagist Total Downloads

This Laravel package allows for batching of Scout updates.

Requirements

  • Laravel Scout 9+
  • Scheduler with cron

Description

This package provides a new trait BatchSearchable that should be used instead of the regular Searchable trait provided by Laravel Scout.

Using that trait, all updates pushed through Scout to the search server (whether it be MeiliSearch, Algolia or whatever else), are batched together instead of being sent one-by-one.

The updates are sent on two possible conditions:

Either scout.batch_searchable_max_batch_size (default 250) is exeeded

or

scout.batch_searchable_debounce_time_in_min (default 1) minutes have passed from the last update to the pending queue

The IDs of models that require updating are stored in the default cache layer using the Cache helper.

The debounce check uses Laravel's Scheduler to schedule a job that checks through all the pending update queues and sees if the required time has passed. This requires that the system has a working cron setup that calls schedule:run every minute.

Installation

Install the package in a Laravel Nova project via Composer and run migrations:

composer require optimistdigital/laravel-scout-batch-searchable

Usage

Where you previously used the Searchable trait, just use BatchSearchable instead:

use OptimistDigital\ScoutBatchSearchable\BatchSearchable;

class SomeModel extends Model {
    use BatchSearchable;
}

Credits

License

Laravel Scout Batch Searchable is open-sourced software licensed under the MIT license.

Comments
  • Adding model to batchSearchableModels

    Adding model to batchSearchableModels

    Hi there, thanks for this package, needed this feature to solve rate limits with my elasticsearch host.

    Just FYI, I had to add this line to my AppServiceProvider boot method:

    ScoutBatchSearchableServiceProvider::$batchSearchableModels[] = Item::class;

    In order to get the scheduled command working.

    Let me know if I missed something!

    opened by keithbrink 5
  • composer require: Could not find a matching version of package

    composer require: Could not find a matching version of package

    Getting this error when trying to require the package:
    Could not find a matching version of package outl1ne/laravel-scout-batch-searchable. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (dev).

    Was having a similar issue earlier this week with manogi/nova-tiptap which had a dependancy on your outl1ne/nova-tailwind package. I was unable to resolve that, luckily the latest version of manogi/nova-tiptap removed the nova-tailwind dependancy.

    opened by phpMagpie 1
  • Ensure batch object has batchable methods

    Ensure batch object has batchable methods

    I am encountering a bug in production where there is a class in the BATCH_SEARCHABLE_QUEUED_MODELS cache that does not use the BatchSearchable, leading to an expection being thrown every minute by the scheduler.

    This PR patches the bug but doesn't resolve the underlying problem with the incorrect class being added to the Cache.

    It looks like this happens because this package overrides the searchable method on the base Collection, so if that is called and the collection contains objects that do not have the BatchSearchable trait, it will still add those classes to the BATCH_SEARCHABLE_QUEUED_MODELS cache.

    Edit: I was incorrect about the scheduler not processing the rest of the commands.

    opened by keithbrink 1
  • Add method to immediately queue the search updates

    Add method to immediately queue the search updates

    Sometimes it's helpful to have the option to immediately send a searchable model to be updated, rather than waiting for the batch, such as when the user might want to immediately use a model they created.

    This adds a macro to skip the batching and send the update directly to the parent searchable trait method.

    I also added the illuminate/support package and replaced the global functions with their facades so that IDEs can understand the classes.

    opened by keithbrink 1
  • Use scout config chunk sizes

    Use scout config chunk sizes

    Would it make sense to use Scout's already defined chunk sizes for batching, instead of defining one explicitly?

    'chunk' => [
        'searchable'   => 500,
        'unsearchable' => 500,
    ],
    
    opened by FrittenKeeZ 1
Releases(2.0.0)
Owner
Optimist Digital
Digital product agency based in Tallinn, Estonia.
Optimist Digital
Driver for Laravel Scout search package based on tntsearch

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

TNT Studio 1k Dec 27, 2022
Laravel IndexNow - Submit webpage updates to search engines

Laravel IndexNow - Submit webpage updates to search engines This packages provides a wrapper to use the IndexNow api in Laravel. This makes indexing n

Laravel Freelancer NL 26 Dec 27, 2022
Scout Extended: The Full Power of Algolia in Laravel

Documentation • Community Forum • Stack Overflow • Report a bug • FAQ • Support To dig right in, visit the Scout Extended documentation. Scout Extende

Algolia 378 Dec 1, 2022
This package allows you to easily track your laravel jobs!

Trackable Jobs For Laravel This package allows you to track your laravel jobs! Using this package, you can easily persist the output and the status of

Mateus Junges 220 Dec 25, 2022
Save Model is a Laravel package that allows you to save data in the database in a new way.

Save Model is a Laravel package that allows you to save data in the database in a new way. No need to worry about $guarded and $fillable properties in the model anymore. Just relax an use Save Model package.

Laratips 27 Mar 2, 2022
🖖Repository Pattern in Laravel. The package allows to filter by request out-of-the-box, as well as to integrate customized criteria and any kind of filters.

Repository Repository Pattern in Laravel. The package allows to filter by request out-of-the-box, as well as to integrate customized criteria and any

Awes.io 160 Dec 26, 2022
Vandar Cashier is a Laravel package that allows you to seamlessly implement IPG and Direct Debit on your application

Vandar Cashier is a Laravel package that provides you with a seamless integration with Vandar services. Take a look at Vandar Documentation for more i

Vandar 11 Dec 14, 2022
This package provides a Logs page that allows you to view your Laravel log files in a simple UI

A simplistics log viewer for your Filament apps. This package provides a Logs page that allows you to view your Laravel log files in a simple UI. Inst

Ryan Chandler 9 Sep 17, 2022
A Laravel package that allows you to use multiple ".env" files in a precedent manner. Use ".env" files per domain (multi-tentant)!

Laravel Multi ENVs Use multiple .envs files and have a chain of precedence for the environment variables in these different .envs files. Use the .env

Allyson Silva 48 Dec 29, 2022
This package allows you to easily work with NanoID in your Laravel models.

Laravel Model UUIDs Introduction Huge thanks to Micheal Dyrynda, whose work inspired me to create this package based on laravel-model-nanoid but uses

Parables Boltnoel 3 Jul 27, 2022
A Laravel package that allows you to validate your config values and environment.

Table of Contents Overview Installation Requirements Install the Package Publishing the Default Rulesets Usage Creating a Validation Ruleset Using the

Ash Allen 152 Dec 15, 2022
This Laravel Nova package allows you to manage media and media fields

Nova Media Hub This Laravel Nova package allows you to manage media and media fields. Requirements php: >=8.0 laravel/nova: ^4.0 Features Media Hub UI

outl1ne 25 Dec 22, 2022
This package allows you to render livewire components like a blade component, giving it attributes, slots etc

X-livewire This package allows you to render livewire components like a blade component, giving it attributes, slots etc. Assuming you wanted to creat

null 7 Nov 15, 2022
Laravel Impersonate is a plugin that allows you to authenticate as your users.

Laravel Impersonate Laravel Impersonate makes it easy to authenticate as your users. Add a simple trait to your user model and impersonate as one of y

404lab 1.6k Dec 30, 2022
A simple Content Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc.

Laravel Moderation A simple Moderation System for Laravel 5.* that allows you to Approve or Reject resources like posts, comments, users, etc. Keep yo

Alex Kyriakidis 509 Dec 30, 2022
A Laravel wrapper for spatie/dns. Allows to query and validate DNS records.

A Laravel wrapper for spatie/dns. Allows to query and validate DNS records.

Astrotomic 22 Nov 17, 2022
Collection of the Laravel/Eloquent Model classes that allows you to get data directly from a Magento 2 database.

Laragento LAravel MAgento Micro services Magento 2 has legacy code based on abandoned Zend Framework 1 with really ugly ORM on top of outdated Zend_DB

Egor Shitikov 87 Nov 26, 2022
The missing laravel helper that allows you to inspect your eloquent queries with it's bind parameters

Laravel Query Inspector The missing laravel helper that allows you to ispect your eloquent queries with it's bind parameters Motivations Let's say you

Mouad ZIANI 59 Sep 25, 2022
Allows you to use Twig seamlessly in Laravel

Allows you to use Twig seamlessly in Laravel. Requirements TwigBridge >= 0.13 supports Twig 3. If you need Twig 1/2 support, use the 0.12 versions. In

Rob Crowe 877 Dec 30, 2022