Searchable
trait Searchable mixin Model
Provides full-text search capabilities to Eloquent models.
Constants
| SCOUT_RUNNER_CONTEXT_KEY |
Coroutine-local context key for the concurrent 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. |
| protected SCOUT_JOBS_CONTEXT_KEY |
Coroutine-local context key for deferred HTTP indexing jobs. |
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.
Details
at line 57
static void
bootSearchable()
Boot the searchable trait.
at line 73
void
registerSearchableMacros()
Register the searchable macros on collections.
Boot-only. These macros persist for the worker lifetime and affect every subsequent request.
at line 139
void
queueMakeSearchable(Collection $models)
Dispatch the job to make the given models searchable.
at line 166
void
syncMakeSearchable(Collection $models)
Synchronously make the given models searchable.
at line 184
void
queueRemoveFromSearch(Collection $models)
Dispatch the job to make the given models unsearchable.
at line 211
void
syncRemoveFromSearch(Collection $models)
Synchronously make the given models unsearchable.
at line 223
bool
shouldBeSearchable()
Determine if the model should be searchable.
at line 231
bool
searchIndexShouldBeUpdated()
When updating a model, this method determines if we should update the search index.
at line 243
static Builder
search(string $query = '', Closure|null $callback = null)
Perform a search against the model's indexed data.
Models may define a protected static class-string
at line 259
static void
makeAllSearchable(int|null $chunk = null)
Make all instances of the model searchable.
at line 267
static Builder
makeAllSearchableQuery()
Get a query builder for making all instances of the model searchable.
at line 284
Collection
makeSearchableUsing(Collection $models)
Modify the collection of models being made searchable.
at line 292
protected Builder
makeAllSearchableUsing(Builder $query)
Modify the query used to retrieve models when making all of the models searchable.
at line 300
void
searchable()
Make the given model instance searchable.
at line 308
void
searchableSync()
Synchronously make the given model instance searchable.
at line 316
static void
removeAllFromSearch(bool $force = false)
Remove all instances of the model from the search index.
at line 329
void
unsearchable()
Remove the given model instance from the search index.
at line 337
void
unsearchableSync()
Synchronously remove the given model instance from the search index.
at line 345
bool
wasSearchableBeforeUpdate()
Determine if the model existed in the search index prior to an update.
at line 353
bool
wasSearchableBeforeDelete()
Determine if the model existed in the search index prior to deletion.
at line 364
Collection
getScoutModelsByIds(Builder $builder, array $ids)
Get the requested models from an array of object IDs.
at line 375
Builder
queryScoutModelsByIds(Builder $builder, array $ids)
Get a query builder for retrieving the requested models from an array of object IDs.
at line 398
static void
enableSearchSyncing()
Enable search syncing for this model.
at line 406
static void
disableSearchSyncing()
Disable search syncing for this model.
at line 414
static bool
isSearchSyncingEnabled()
Determine if search syncing is enabled for this model.
at line 422
static mixed
withoutSyncingToSearch(callable $callback)
Temporarily disable search syncing for the given callback.
at line 438
string
searchableAs()
Get the index name for the model when searching.
at line 446
string
indexableAs()
Get the index name for the model when indexing.
at line 454
array
toSearchableArray()
Get the indexable data array for the model.
at line 462
Engine
searchableUsing()
Get the Scout engine for the model.
at line 470
string|null
syncWithSearchUsing()
Get the queue connection that should be used when syncing.
at line 478
string|null
syncWithSearchUsingQueue()
Get the queue that should be used with syncing.
at line 488
Searchable
pushSoftDeleteMetadata()
Sync the soft deleted status for this model into the metadata.
at line 496
array
scoutMetadata()
Get all Scout related metadata.
at line 506
Searchable
withScoutMetadata(string $key, mixed $value)
Set a Scout related metadata.
at line 516
mixed
getScoutKey()
Get the value used to index the model.
at line 533
string
getScoutKeyName()
Get the key name used to index the model.
at line 541
string
getScoutKeyType()
Get the auto-incrementing key type for querying models.
at line 549
static protected void
dispatchSearchableJob(callable $job)
Dispatch the job to scout the given models.
at line 601
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 617
static protected bool
usesSoftDelete()
Determine if the current class should use soft deletes with searching.