class Scout

Scout utility class for lifecycle customization and engine access.

Provides static configuration for customizing the job classes used when indexing models via the queue. Set these in a service provider boot method to use custom job implementations.

Note: These static properties are set at boot time and read during request handling. Job classes are stable strings, while lifecycle callbacks may capture objects and therefore must never be registered from request handling.

Constants

protected DEFAULT_MAKE_SEARCHABLE_JOB

The default job class that makes models searchable.

protected DEFAULT_REMOVE_FROM_SEARCH_JOB

The default job class that removes models from the search index.

DEFAULT_CHUNK_SIZE

The default number of models processed in each search indexing chunk.

IMPORTING_CONTEXT_KEY

Coroutine-local context key indicating that scout:import is currently running.

Coroutine-local rather than process-global so concurrent coroutines in the same process don't leak the import flag into each other.

IMPORT_PROGRESS_CONTEXT_KEY

Coroutine-local context key for the active scout:import progress reporter.

Properties

static MakeSearchable> $makeSearchableJob

The job class that makes models searchable.

static RemoveFromSearch> $removeFromSearchJob

The job class that removes models from the search index.

static protected null|Engine): void $prepareBuilderCallback

The callback that prepares a Builder before terminal execution.

static protected null|Engine): array<string, mixed> $prepareSearchableDocumentCallback

The callback that prepares a final searchable document.

static protected null|Closure(array<string, mixed>, null|Engine, string): array<string, mixed> $prepareIndexSettingsCallback

The callback that prepares final index settings.

static protected null|Engine, bool): void $guardModelFlushCallback

The callback that guards a whole-model index flush.

Methods

static Engine
engine(string|null $name = null)

Get a Scout engine instance by name.

static void
prepareBuilderUsing(callable $callback)

Specify the callback that prepares a Builder before terminal execution.

static void
prepareBuilder(Builder $builder, Engine $engine)

Prepare a Builder before terminal execution.

static void
prepareSearchableDocumentUsing(callable $callback)

Specify the callback that prepares a final searchable document.

static array
prepareSearchableDocument(array $document, Model $model, Engine $engine)

Prepare a final searchable document.

static void
prepareIndexSettingsUsing(callable $callback)

Specify the callback that prepares final index settings.

static array
prepareIndexSettings(array $settings, Model|null $model, Engine $engine, string $index)

Prepare final index settings.

static void
guardModelFlushUsing(callable $callback)

Specify the callback that guards a whole-model index flush.

static void
guardModelFlush(Model $model, Engine $engine, bool $force)

Guard a whole-model index flush.

static void
makeSearchableUsing(string $class)

Specify the job class that should make models searchable.

static void
removeFromSearchUsing(string $class)

Specify the job class that should remove models from the search index.

static mixed
whileImporting(callable $callback)

Run the given callback with the "importing" flag set in the current coroutine.

static bool
isImporting()

Determine whether scout:import is currently running in this coroutine.

static mixed
whileReportingImportProgress(callable $reporter, callable $callback)

Run the given callback with an import progress reporter in the current coroutine.

static void
reportImportProgress(Collection $models)

Report imported models to the current coroutine's scout:import progress reporter.

static void
flushState()

Flush all static state.

Details

at line 102
static Engine engine(string|null $name = null)

Get a Scout engine instance by name.

Parameters

string|null $name

Return Value

Engine

at line 115
static void prepareBuilderUsing(callable $callback)

Specify the callback that prepares a Builder before terminal execution.

Boot-only. The callback persists for the worker lifetime, so registering it per request would leak captured request state into later requests.

Parameters

callable $callback

Return Value

void

at line 123
static void prepareBuilder(Builder $builder, Engine $engine)

Prepare a Builder before terminal execution.

Parameters

Builder $builder
Engine $engine

Return Value

void

at line 138
static void prepareSearchableDocumentUsing(callable $callback)

Specify the callback that prepares a final searchable document.

Boot-only. The callback persists for the worker lifetime, so registering it per request would leak captured request state into later requests.

Parameters

callable $callback

Return Value

void

at line 150
static array prepareSearchableDocument(array $document, Model $model, Engine $engine)

Prepare a final searchable document.

Parameters

array $document
Model $model
Engine $engine

Return Value

array

at line 165
static void prepareIndexSettingsUsing(callable $callback)

Specify the callback that prepares final index settings.

Boot-only. The callback persists for the worker lifetime, so registering it per request would leak captured request state into later requests.

Parameters

callable $callback

Return Value

void

at line 177
static array prepareIndexSettings(array $settings, Model|null $model, Engine $engine, string $index)

Prepare final index settings.

Parameters

array $settings
Model|null $model
Engine $engine
string $index

Return Value

array

at line 192
static void guardModelFlushUsing(callable $callback)

Specify the callback that guards a whole-model index flush.

Boot-only. The callback persists for the worker lifetime, so registering it per request would leak captured request state into later requests.

Parameters

callable $callback

Return Value

void

at line 200
static void guardModelFlush(Model $model, Engine $engine, bool $force)

Guard a whole-model index flush.

Parameters

Model $model
Engine $engine
bool $force

Return Value

void

at line 215
static void makeSearchableUsing(string $class)

Specify the job class that should make models searchable.

Boot-only. The job class persists in a static property for the worker lifetime and is used by every subsequent searchable import.

Parameters

string $class

Return Value

void

at line 228
static void removeFromSearchUsing(string $class)

Specify the job class that should remove models from the search index.

Boot-only. The job class persists in a static property for the worker lifetime and is used by every subsequent searchable removal.

Parameters

string $class

Return Value

void

at line 240
static mixed whileImporting(callable $callback)

Run the given callback with the "importing" flag set in the current coroutine.

The previous context state is captured before the call and restored in finally. This makes the helper nesting-safe: an inner whileImporting() call won't clear an outer call's flag when it returns.

Parameters

callable $callback

Return Value

mixed

at line 261
static bool isImporting()

Determine whether scout:import is currently running in this coroutine.

Return Value

bool

at line 271
static mixed whileReportingImportProgress(callable $reporter, callable $callback)

Run the given callback with an import progress reporter in the current coroutine.

Parameters

callable $reporter
callable $callback

Return Value

mixed

at line 294
static void reportImportProgress(Collection $models)

Report imported models to the current coroutine's scout:import progress reporter.

Parameters

Collection $models

Return Value

void

at line 306
static void flushState()

Flush all static state.

Return Value

void