Builder
class Builder
Fluent search query builder for searchable models.
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| SearchableInterface&TModel | $model | The model instance. |
|
| string | $query | The query expression. |
|
| Closure|null | $callback | Optional callback before search execution. |
|
| Closure|null | $queryCallback | Optional callback before model query execution. |
|
| Closure|null | $afterRawSearchCallback | Optional callback after raw search. |
|
| string|null | $index | The custom index specified for the search. |
|
| array<int, array{field: string, operator: string, value: mixed}> | $wheres | The "where" constraints added to the query. |
|
| array<string, mixed[]> | $whereIns | The "where in" constraints added to the query. |
|
| array<string, mixed[]> | $whereNotIns | The "where not in" constraints added to the query. |
|
| int|null | $limit | The "limit" that should be applied to the search. |
|
| array<array{column: string, direction: string}> | $orders | The "order" that should be applied to the search. |
|
| bool | $semanticSearch | Indicates that the query should use semantic search. |
|
| float|int|null | $minimumSimilarity | The minimum similarity for semantic search results. |
|
| null|array{text_weight: float|int, semantic_weight: float|int} | $hybridSearch | The hybrid search ranking weights. |
|
| array<string, mixed> | $options | Extra options that should be applied to the search. |
Methods
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Call the given Closure with this instance then return the instance.
Create a new search builder instance.
Add a constraint to the search query.
Add a "where not in" constraint to the search query.
Include soft deleted records in the results.
Include only soft deleted records in the results.
Add a descending "order by" clause to the search query.
Add an "order by" clause for a timestamp to the query (descending).
Add an "order by" clause for a timestamp to the query (ascending).
Perform a semantic search for the query expression.
Perform a hybrid full-text and semantic search for the query expression.
Set the callback that should have an opportunity to modify the database query.
Get the raw results of the search.
Set the callback that should have an opportunity to inspect and modify the raw result returned by the search engine.
Get the keys of search results.
Get the results of the search.
Get the results of the search as a lazy collection.
Paginate the given query into a simple paginator.
Paginate the given query into a length-aware paginator.
Paginate the given query into a length-aware paginator with raw data.
Paginate the given query into a simple paginator with raw data.
Get the total number of results from the Scout engine, or fallback to query builder.
Invoke the "after raw search" callback.
Get the prepared engine that should handle the query.
Get the connection type for the underlying model.
Flush all static state.
Details
in
Conditionable at line 23
mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
in
Conditionable at line 56
mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) falsy.
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
Tappable at line 17
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
at line 135
__construct(Model $model, string|null $query, Closure|null $callback = null, bool $softDelete = false)
Create a new search builder instance.
at line 160
Builder
within(string $index)
Specify a custom index for search or filtered deletion.
at line 172
Builder
where(string $field, mixed $operator, mixed $value = null)
Add a constraint to the search query.
at line 192
Builder
whereIn(string $field, array|Arrayable $values)
Add a "where in" constraint to the search query.
at line 209
Builder
whereNotIn(string $field, array|Arrayable $values)
Add a "where not in" constraint to the search query.
at line 225
Builder
withTrashed()
Include soft deleted records in the results.
at line 240
Builder
onlyTrashed()
Include only soft deleted records in the results.
at line 256
Builder
take(int $limit)
Set the "limit" for the search query.
at line 268
Builder
orderBy(string $column, string $direction = 'asc')
Add an "order" for the search query.
at line 283
Builder
orderByDesc(string $column)
Add a descending "order by" clause to the search query.
at line 293
Builder
latest(string|null $column = null)
Add an "order by" clause for a timestamp to the query (descending).
at line 305
Builder
oldest(string|null $column = null)
Add an "order by" clause for a timestamp to the query (ascending).
at line 317
Builder
semantic(float|int|null $minSimilarity = null)
Perform a semantic search for the query expression.
at line 335
Builder
hybrid(float|int $textWeight = 1, float|int $semanticWeight = 1, float|int|null $minSimilarity = null)
Perform a hybrid full-text and semantic search for the query expression.
at line 365
Builder
options(array $options)
Set extra options for the search query.
at line 377
Builder
query(callable $callback)
Set the callback that should have an opportunity to modify the database query.
at line 387
mixed
raw()
Get the raw results of the search.
at line 398
Builder
withRawResults(callable $callback)
Set the callback that should have an opportunity to inspect and modify the raw result returned by the search engine.
at line 408
Collection
keys()
Get the keys of search results.
at line 418
Model|null
first()
Get the first result from the search.
at line 428
Collection
get()
Get the results of the search.
at line 438
LazyCollection
cursor()
Get the results of the search as a lazy collection.
at line 446
Paginator
simplePaginate(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator.
at line 499
LengthAwarePaginator
paginate(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a length-aware paginator.
at line 551
LengthAwarePaginator
paginateRaw(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a length-aware paginator with raw data.
at line 596
Paginator
simplePaginateRaw(int|null $perPage = null, string $pageName = 'page', int|null $page = null)
Paginate the given query into a simple paginator with raw data.
at line 643
protected int
getTotalCount(mixed $results)
Get the total number of results from the Scout engine, or fallback to query builder.
at line 672
mixed
applyAfterRawSearchCallback(mixed $results)
Invoke the "after raw search" callback.
at line 684
protected Engine
preparedEngine()
Get the prepared engine that should handle the query.
at line 701
protected Engine
engine()
Get the engine that should handle the query.
at line 709
string
modelConnectionType()
Get the connection type for the underlying model.
at line 720
static void
flushState()
Flush all static state.