class Scout

Scout utility class for job 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. This is safe in Swoole/coroutine environments because they store class names (strings), not stateful objects.

Constants

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.

Methods

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

Get a Scout engine instance by name.

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 58
static Engine engine(string|null $name = null)

Get a Scout engine instance by name.

Parameters

string|null $name

Return Value

Engine

at line 71
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 84
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 96
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 117
static bool isImporting()

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

Return Value

bool

at line 127
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 150
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 162
static void flushState()

Flush all static state.

Return Value

void