Searchable
trait Searchable mixin Model
Provides full-text search capabilities to Eloquent models.
Constants
| SCOUT_RUNNER_CONTEXT_KEY |
Coroutine-local context key for the WaitConcurrent runner used during imports. Coroutine-local rather than a static property so concurrent coroutines in the same process don't share or overwrite each other's runner instances. |
Properties
| protected array<string, mixed> | $scoutMetadata | Additional metadata attributes managed by Scout. |
Methods
Boot the searchable trait.
Register the searchable macros on collections.
Determine if the model should be searchable.
When updating a model, this method determines if we should update the search index.
Make all instances of the model searchable.
Get a query builder for making all instances of the model searchable.
Modify the query used to retrieve models when making all of the models searchable.
Make the given model instance searchable.
Synchronously make the given model instance searchable.
Remove all instances of the model from the search index.
Remove the given model instance from the search index.
Synchronously remove the given model instance from the search index.
Determine if the model existed in the search index prior to an update.
Determine if the model existed in the search index prior to deletion.
Get the requested models from an array of object IDs.
Get a query builder for retrieving the requested models from an array of object IDs.
Enable search syncing for this model.
Disable search syncing for this model.
Determine if search syncing is enabled for this model.
Temporarily disable search syncing for the given callback.
Get the index name for the model when searching.
Get the index name for the model when indexing.
Get the indexable data array for the model.
Get the Scout engine for the model.
Get the queue connection that should be used when syncing.
Get the queue that should be used with syncing.
Sync the soft deleted status for this model into the metadata.
Get all Scout related metadata.
Set a Scout related metadata.
Get the value used to index the model.
Get the key name used to index the model.
Get the auto-incrementing key type for querying models.
Dispatch the job to scout the given models.
Wait for all pending searchable jobs to complete.
Determine if the current class should use soft deletes with searching.
Get a Scout configuration value.
Details
at line 43
static void
bootSearchable()
Boot the searchable trait.
at line 57
void
registerSearchableMacros()
Register the searchable macros on collections.
at line 91
void
queueMakeSearchable(Collection $models)
Dispatch the job to make the given models searchable.
at line 118
void
syncMakeSearchable(Collection $models)
Synchronously make the given models searchable.
at line 136
void
queueRemoveFromSearch(Collection $models)
Dispatch the job to make the given models unsearchable.
at line 163
void
syncRemoveFromSearch(Collection $models)
Synchronously make the given models unsearchable.
at line 175
bool
shouldBeSearchable()
Determine if the model should be searchable.
at line 183
bool
searchIndexShouldBeUpdated()
When updating a model, this method determines if we should update the search index.
at line 193
static Builder
search(string $query = '', Closure|null $callback = null)
Perform a search against the model's indexed data.
at line 206
static void
makeAllSearchable(int|null $chunk = null)
Make all instances of the model searchable.
at line 214
static Builder
makeAllSearchableQuery()
Get a query builder for making all instances of the model searchable.
at line 231
Collection
makeSearchableUsing(Collection $models)
Modify the collection of models being made searchable.
at line 239
protected Builder
makeAllSearchableUsing(Builder $query)
Modify the query used to retrieve models when making all of the models searchable.
at line 247
void
searchable()
Make the given model instance searchable.
at line 255
void
searchableSync()
Synchronously make the given model instance searchable.
at line 263
static void
removeAllFromSearch()
Remove all instances of the model from the search index.
at line 272
void
unsearchable()
Remove the given model instance from the search index.
at line 280
void
unsearchableSync()
Synchronously remove the given model instance from the search index.
at line 288
bool
wasSearchableBeforeUpdate()
Determine if the model existed in the search index prior to an update.
at line 296
bool
wasSearchableBeforeDelete()
Determine if the model existed in the search index prior to deletion.
at line 304
Collection
getScoutModelsByIds(Builder $builder, array $ids)
Get the requested models from an array of object IDs.
at line 312
Builder
queryScoutModelsByIds(Builder $builder, array $ids)
Get a query builder for retrieving the requested models from an array of object IDs.
at line 335
static void
enableSearchSyncing()
Enable search syncing for this model.
at line 343
static void
disableSearchSyncing()
Disable search syncing for this model.
at line 351
static bool
isSearchSyncingEnabled()
Determine if search syncing is enabled for this model.
at line 359
static mixed
withoutSyncingToSearch(callable $callback)
Temporarily disable search syncing for the given callback.
at line 373
string
searchableAs()
Get the index name for the model when searching.
at line 381
string
indexableAs()
Get the index name for the model when indexing.
at line 389
array
toSearchableArray()
Get the indexable data array for the model.
at line 397
Engine
searchableUsing()
Get the Scout engine for the model.
at line 405
string|null
syncWithSearchUsing()
Get the queue connection that should be used when syncing.
at line 413
string|null
syncWithSearchUsingQueue()
Get the queue that should be used with syncing.
at line 423
Searchable
pushSoftDeleteMetadata()
Sync the soft deleted status for this model into the metadata.
at line 431
array
scoutMetadata()
Get all Scout related metadata.
at line 441
Searchable
withScoutMetadata(string $key, mixed $value)
Set a Scout related metadata.
at line 451
mixed
getScoutKey()
Get the value used to index the model.
at line 459
string
getScoutKeyName()
Get the key name used to index the model.
at line 467
string
getScoutKeyType()
Get the auto-incrementing key type for querying models.
at line 475
static protected void
dispatchSearchableJob(callable $job)
Dispatch the job to scout the given models.
at line 502
static void
waitForSearchableJobs()
Wait for all pending searchable jobs to complete.
Should be called at the end of Scout commands to ensure all concurrent indexing operations have finished.
at line 515
static protected bool
usesSoftDelete()
Determine if the current class should use soft deletes with searching.
at line 523
static protected mixed
getScoutConfig(string $key, mixed $default = null)
Get a Scout configuration value.