Scout
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
Specify the callback that prepares a Builder before terminal execution.
Specify the callback that prepares a final searchable document.
Prepare a final searchable document.
Specify the callback that prepares final index settings.
Prepare final index settings.
Specify the callback that guards a whole-model index flush.
Specify the job class that should make models searchable.
Specify the job class that should remove models from the search index.
Run the given callback with the "importing" flag set in the current coroutine.
Determine whether scout:import is currently running in this coroutine.
Run the given callback with an import progress reporter in the current coroutine.
Report imported models to the current coroutine's scout:import progress reporter.
Flush all static state.
Details
at line 102
static Engine
engine(string|null $name = null)
Get a Scout engine instance by name.
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.
at line 123
static void
prepareBuilder(Builder $builder, Engine $engine)
Prepare a Builder before terminal execution.
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.
at line 150
static array
prepareSearchableDocument(array $document, Model $model, Engine $engine)
Prepare a final searchable document.
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.
at line 177
static array
prepareIndexSettings(array $settings, Model|null $model, Engine $engine, string $index)
Prepare final index settings.
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.
at line 200
static void
guardModelFlush(Model $model, Engine $engine, bool $force)
Guard a whole-model index flush.
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.
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.
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.
at line 261
static bool
isImporting()
Determine whether scout:import is currently running in this coroutine.
at line 271
static mixed
whileReportingImportProgress(callable $reporter, callable $callback)
Run the given callback with an import progress reporter in the current coroutine.
at line 294
static void
reportImportProgress(Collection $models)
Report imported models to the current coroutine's scout:import progress reporter.
at line 306
static void
flushState()
Flush all static state.