class CollectionEngine extends Engine

In-memory search engine using database queries and Collection filtering.

Useful for testing without requiring an external search service.

Properties

protected EngineOperationRunner|null $operationRunner

The operation runner assigned to this engine.

from  Engine
protected string $operationRunnerEngineName

The configured name of this engine.

from  Engine

Methods

void
update(Collection $models)

Update the given models in the search index.

void
delete(Collection $models)

Remove the given models from the search index.

mixed
search(Builder $builder)

Perform a search against the engine.

mixed
paginate(Builder $builder, int $perPage, int $page)

Perform a paginated search against the engine.

mapIds(mixed $results)

Pluck and return the primary keys of the given results.

map(Builder $builder, mixed $results, Model $model)

Map the given results to instances of the given model.

lazyMap(Builder $builder, mixed $results, Model $model)

Map the given results to instances of the given model via a lazy collection.

int
getTotalCount(mixed $results)

Get the total count from a raw result returned by the engine.

void
flush(Model $model)

Flush all of the model's records from the engine.

mixed
createIndex(string $name, array $options = [])

Create a search index.

mixed
deleteIndex(string $name)

Delete a search index.

setOperationRunner(EngineOperationRunner $runner, string $engineName)

Assign the operation runner to this engine.

from  Engine
bool
hasObservableOperations()

Determine if this engine has operations worth observing.

from  Engine
void
runUpdate(Collection $models)

Update the given models without observing an external index operation.

void
runDelete(Collection $models)

Delete the given models without observing an external index operation.

mixed
runSearch(Builder $builder)

Search through the operation runner.

from  Engine
mixed
runPaginate(Builder $builder, int $perPage, int $page)

Paginate through the operation runner.

from  Engine
void
runFlush(Model $model)

Flush the given model without observing an external index operation.

mixed
runOperation(string $operation, Builder $builder, Closure $callback, string|null $index = null)

Run a Builder operation through the operation runner.

from  Engine
mapIdsFrom(mixed $results, string $key)

Pluck and return the primary keys of the given results using the given key name.

from  Engine
keys(Builder $builder)

Get the results of the query as a Collection of primary keys.

from  Engine
get(Builder $builder)

Get the results of the given query mapped onto models.

from  Engine
cursor(Builder $builder)

Get a lazy collection for the given query mapped onto models.

from  Engine
searchModels(Builder $builder)

Get the Eloquent models for the given builder.

ensureSoftDeletesAreHandled(Builder $builder, Builder $query)

Ensure that soft delete handling is properly applied to the query.

Details

at line 27
void update(Collection $models)

Update the given models in the search index.

Parameters

Collection $models

Return Value

void

at line 43
void delete(Collection $models)

Remove the given models from the search index.

Parameters

Collection $models

Return Value

void

Perform a search against the engine.

Parameters

Builder $builder

Return Value

mixed

at line 83
mixed paginate(Builder $builder, int $perPage, int $page)

Perform a paginated search against the engine.

Parameters

Builder $builder
int $perPage
int $page

Return Value

mixed

at line 209
Collection mapIds(mixed $results)

Pluck and return the primary keys of the given results.

Parameters

mixed $results

Return Value

Collection

at line 224
Collection map(Builder $builder, mixed $results, Model $model)

Map the given results to instances of the given model.

Parameters

Builder $builder
mixed $results
Model $model

Return Value

Collection

at line 253
LazyCollection lazyMap(Builder $builder, mixed $results, Model $model)

Map the given results to instances of the given model via a lazy collection.

Parameters

Builder $builder
mixed $results
Model $model

Return Value

LazyCollection

at line 281
int getTotalCount(mixed $results)

Get the total count from a raw result returned by the engine.

Parameters

mixed $results

Return Value

int

at line 289
void flush(Model $model)

Flush all of the model's records from the engine.

Parameters

Model $model

Return Value

void

at line 305
mixed createIndex(string $name, array $options = [])

Create a search index.

Parameters

string $name
array $options

Return Value

mixed

at line 313
mixed deleteIndex(string $name)

Delete a search index.

Parameters

string $name

Return Value

mixed

in Engine at line 102
Engine setOperationRunner(EngineOperationRunner $runner, string $engineName)

Assign the operation runner to this engine.

Boot-only. The runner persists on this engine for the worker lifetime. Engines without observable operations retain no runner.

Parameters

EngineOperationRunner $runner
string $engineName

Return Value

Engine

in Engine at line 117
protected bool hasObservableOperations()

Determine if this engine has operations worth observing.

Return Value

bool

at line 35
void runUpdate(Collection $models)

Update the given models without observing an external index operation.

Parameters

Collection $models

Return Value

void

at line 51
void runDelete(Collection $models)

Delete the given models without observing an external index operation.

Parameters

Collection $models

Return Value

void

in Engine at line 185
mixed runSearch(Builder $builder)

Search through the operation runner.

Parameters

Builder $builder

Return Value

mixed

in Engine at line 205
mixed runPaginate(Builder $builder, int $perPage, int $page)

Paginate through the operation runner.

Parameters

Builder $builder
int $perPage
int $page

Return Value

mixed

at line 297
void runFlush(Model $model)

Flush the given model without observing an external index operation.

Parameters

Model $model

Return Value

void

in Engine at line 255
mixed runOperation(string $operation, Builder $builder, Closure $callback, string|null $index = null)

Run a Builder operation through the operation runner.

An omitted index uses the Builder's configured or searchable index. Pass an explicit index when the operation targets another dataset.

Parameters

string $operation
Builder $builder
Closure $callback
string|null $index

Return Value

mixed

in Engine at line 281
Collection mapIdsFrom(mixed $results, string $key)

Pluck and return the primary keys of the given results using the given key name.

Parameters

mixed $results
string $key

Return Value

Collection

in Engine at line 289
Collection keys(Builder $builder)

Get the results of the query as a Collection of primary keys.

Parameters

Builder $builder

Return Value

Collection

in Engine at line 297
Collection get(Builder $builder)

Get the results of the given query mapped onto models.

Parameters

Builder $builder

Return Value

Collection

in Engine at line 309
LazyCollection cursor(Builder $builder)

Get a lazy collection for the given query mapped onto models.

Parameters

Builder $builder

Return Value

LazyCollection

at line 99
protected Collection searchModels(Builder $builder)

Get the Eloquent models for the given builder.

Parameters

Builder $builder

Return Value

Collection

at line 182
protected Builder ensureSoftDeletesAreHandled(Builder $builder, Builder $query)

Ensure that soft delete handling is properly applied to the query.

The withTrashed/onlyTrashed/withoutTrashed methods are added dynamically by SoftDeletingScope. We guard these calls with runtime checks for SoftDeletes usage, making them safe but not statically analyzable.

Parameters

Builder $builder
Builder $query

Return Value

Builder