class DatabaseEngine extends Engine implements PaginatesEloquentModelsUsingDatabase

Database search engine implementation.

Searches directly in the database using LIKE queries and optional full-text search. This engine requires no external services and works with any database that Hypervel supports.

Properties

protected Model>, array<class-string, string[]>> $attributeColumns

Cached searchable attribute columns by model class and attribute class.

protected Model>, array<string, mixed>> $fullTextOptions

Cached full-text options by model class.

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.

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
paginateUsingDatabase(Builder $builder, int $perPage, string $pageName, int $page)

Paginate the given search on the engine using database pagination.

simplePaginateUsingDatabase(Builder $builder, int $perPage, string $pageName, int $page)

Paginate the given search on the engine using simple database pagination.

searchModels(Builder $builder, int|null $page = null, int|null $perPage = null)

Get the Eloquent models for the given builder.

buildSearchQuery(Builder $builder)

Initialize / build the search query for the given Scout builder.

initializeSearchQuery(Builder $builder, array $columns, array $prefixColumns = [], array $fullTextColumns = [])

Build the initial text search database query for all relevant columns.

bool
shouldOrderByRelevance(Builder $builder)

Determine if the query should be ordered by relevance.

orderByRelevance(Builder $builder, Builder $query)

Add an "order by" clause that orders by relevance (Postgres only).

addAdditionalConstraints(Builder $builder, Builder $query)

Add additional, developer defined constraints to the search query.

constrainForSoftDeletes(Builder $builder, Builder $query)

Ensure that soft delete constraints are properly applied to the query.

array
getFullTextColumns(Builder $builder)

Get the full-text columns for the query.

array
getPrefixColumns(Builder $builder)

Get the prefix search columns for the query.

array
getAttributeColumns(Builder $builder, string $attributeClass)

Get the columns marked with a given attribute.

array
getFullTextOptions(Builder $builder)

Get the full-text search options for the query.

mixed
getConfig(string $key, mixed $default = null)

Get a Scout configuration value.

Details

at line 482
void update(Collection $models)

Update the given models in the search index.

The database engine doesn't need to update an external index.

Parameters

Collection $models

Return Value

void

at line 494
void delete(Collection $models)

Remove the given models from the search index.

The database engine doesn't need to remove from an external index.

Parameters

Collection $models

Return Value

void

Perform a search against the engine.

Parameters

Builder $builder

Return Value

mixed

at line 69
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 433
Collection mapIds(mixed $results)

Pluck and return the primary keys of the given results.

Parameters

mixed $results

Return Value

Collection

at line 449
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 459
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 470
int getTotalCount(mixed $results)

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

Parameters

mixed $results

Return Value

int

at line 504
void flush(Model $model)

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

Parameters

Model $model

Return Value

void

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

Create a search index.

Parameters

string $name
array $options

Return Value

mixed

at line 521
mixed deleteIndex(string $name)

Delete a search index.

Parameters

string $name

Return Value

mixed

in Engine at line 90
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 98
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 106
Collection get(Builder $builder)

Get the results of the given query mapped onto models.

Parameters

Builder $builder

Return Value

Collection

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

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

Parameters

Builder $builder

Return Value

LazyCollection

at line 82
LengthAwarePaginator paginateUsingDatabase(Builder $builder, int $perPage, string $pageName, int $page)

Paginate the given search on the engine using database pagination.

Parameters

Builder $builder
int $perPage
string $pageName
int $page

Return Value

LengthAwarePaginator

at line 109
Paginator simplePaginateUsingDatabase(Builder $builder, int $perPage, string $pageName, int $page)

Paginate the given search on the engine using simple database pagination.

Parameters

Builder $builder
int $perPage
string $pageName
int $page

Return Value

Paginator

at line 138
protected Collection searchModels(Builder $builder, int|null $page = null, int|null $perPage = null)

Get the Eloquent models for the given builder.

Parameters

Builder $builder
int|null $page
int|null $perPage

Return Value

Collection

at line 165
protected Builder buildSearchQuery(Builder $builder)

Initialize / build the search query for the given Scout builder.

Parameters

Builder $builder

Return Value

Builder

at line 189
protected Builder initializeSearchQuery(Builder $builder, array $columns, array $prefixColumns = [], array $fullTextColumns = [])

Build the initial text search database query for all relevant columns.

Parameters

Builder $builder
array $columns
array $prefixColumns
array $fullTextColumns

Return Value

Builder

at line 255
protected bool shouldOrderByRelevance(Builder $builder)

Determine if the query should be ordered by relevance.

Parameters

Builder $builder

Return Value

bool

at line 267
protected Builder orderByRelevance(Builder $builder, Builder $query)

Add an "order by" clause that orders by relevance (Postgres only).

Parameters

Builder $builder
Builder $query

Return Value

Builder

at line 298
protected Builder addAdditionalConstraints(Builder $builder, Builder $query)

Add additional, developer defined constraints to the search query.

Parameters

Builder $builder
Builder $query

Return Value

Builder

at line 329
protected Builder constrainForSoftDeletes(Builder $builder, Builder $query)

Ensure that soft delete constraints are properly applied to the query.

Parameters

Builder $builder
Builder $query

Return Value

Builder

at line 361
protected array getFullTextColumns(Builder $builder)

Get the full-text columns for the query.

Parameters

Builder $builder

Return Value

array

at line 371
protected array getPrefixColumns(Builder $builder)

Get the prefix search columns for the query.

Parameters

Builder $builder

Return Value

array

at line 382
protected array getAttributeColumns(Builder $builder, string $attributeClass)

Get the columns marked with a given attribute.

Parameters

Builder $builder
string $attributeClass

Return Value

array

at line 410
protected array getFullTextOptions(Builder $builder)

Get the full-text search options for the query.

Parameters

Builder $builder

Return Value

array

at line 530
protected mixed getConfig(string $key, mixed $default = null)

Get a Scout configuration value.

Parameters

string $key
mixed $default

Return Value

mixed