TypesenseEngine
class TypesenseEngine extends Engine implements DeletesByFilter
Typesense search engine implementation.
Provides full-text search using Typesense as the backend.
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
Pluck and return the primary keys of the given results.
Get the total count from a raw result returned by the engine.
Create a search index.
Delete a search index.
Assign the operation runner to this engine.
Run a Builder operation through the operation runner.
Pluck and return the primary keys of the given results using the given key name.
Create a new TypesenseEngine instance.
Import the given documents into the index.
Create an import sorting data object for a given document.
Delete a document from the index.
Build the search parameters for a given Scout query builder.
Combine application and Builder filters without changing their precedence.
Parse the given filter value.
Create a "where" filter string.
Create a "where in" filter string.
Create a "where not in" filter string.
Parse the order by fields for the query.
Create the model's Typesense collection.
Get a detached Typesense collection handle.
Get the underlying Typesense client.
Get a Scout configuration value.
Dynamically proxy missing methods to the Typesense client instance.
Details
at line 55
void
update(Collection $models)
Update the given models in the search index.
at line 154
void
delete(Collection $models)
Remove the given models from the search index.
at line 194
mixed
search(Builder $builder)
Perform a search against the engine.
at line 215
mixed
paginate(Builder $builder, int $perPage, int $page)
Perform a paginated search against the engine.
at line 494
Collection
mapIds(mixed $results)
Pluck and return the primary keys of the given results.
at line 506
Collection
map(Builder $builder, mixed $results, Model $model)
Map the given results to instances of the given model.
at line 544
LazyCollection
lazyMap(Builder $builder, mixed $results, Model $model)
Map the given results to instances of the given model via a lazy collection.
at line 573
int
getTotalCount(mixed $results)
Get the total count from a raw result returned by the engine.
at line 583
void
flush(Model $model)
Flush all of the model's records from the engine.
at line 631
mixed
createIndex(string $name, array $options = [])
Create a search index.
at line 643
mixed
deleteIndex(string $name)
Delete a search index.
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.
in
Engine at line 117
protected bool
hasObservableOperations()
Determine if this engine has operations worth observing.
in
Engine at line 127
void
runUpdate(Collection $models)
Update the given models through the operation runner.
in
Engine at line 157
void
runDelete(Collection $models)
Delete the given models through the operation runner.
in
Engine at line 205
mixed
runPaginate(Builder $builder, int $perPage, int $page)
Paginate through the operation runner.
in
Engine at line 225
void
runFlush(Model $model)
Flush the given model through the operation runner.
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.
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.
in
Engine at line 289
Collection
keys(Builder $builder)
Get the results of the query as a Collection of primary keys.
in
Engine at line 297
Collection
get(Builder $builder)
Get the results of the given query mapped onto models.
in
Engine at line 309
LazyCollection
cursor(Builder $builder)
Get a lazy collection for the given query mapped onto models.
at line 43
__construct(Client $typesense, int $maxTotalResults)
Create a new TypesenseEngine instance.
at line 108
protected Collection
importDocuments(Collection $collectionIndex, array $documents, string|null $action = null)
Import the given documents into the index.
at line 136
protected stdClass
createImportSortingDataObject(array $document)
Create an import sorting data object for a given document.
at line 178
protected array
deleteDocument(Collection $collectionIndex, mixed $modelId)
Delete a document from the index.
Returns an empty array if the document doesn't exist (idempotent delete). Other errors (network, auth, etc.) are allowed to bubble up.
at line 237
protected mixed
performSearch(Builder $builder, array $options = [])
Perform the given search on the engine.
at line 261
protected array
performPaginatedSearch(Builder $builder)
Perform a paginated search on the engine.
at line 310
array
buildSearchParameters(Builder $builder, int $page, int|null $perPage)
Build the search parameters for a given Scout query builder.
at line 365
protected string
combineFilters(string $applicationFilters, string $builderFilters)
Combine application and Builder filters without changing their precedence.
at line 381
protected string
filters(Builder $builder)
Prepare the filters for a given search query.
at line 413
protected array|string|int|float
parseFilterValue(array|string|bool|int|float|BackedEnum $value)
Parse the given filter value.
at line 435
protected string
parseWhereFilter(array|string|int|float $value, string $key, string $operator = '=')
Create a "where" filter string.
at line 460
protected string
parseWhereInFilter(array $value, string $key)
Create a "where in" filter string.
at line 470
protected string
parseWhereNotInFilter(array $value, string $key)
Create a "where not in" filter string.
at line 480
protected string
parseOrderBy(array $orders)
Parse the order by fields for the query.
at line 596
void
deleteByFilter(Builder $builder)
Delete every document matching the prepared Builder filters.
at line 654
protected void
createCollectionFromModel(Model $model, string $collectionName)
Create the model's Typesense collection.
at line 678
protected Collection
collection(string $name)
Get a detached Typesense collection handle.
at line 690
protected bool
usesSoftDelete(Model $model)
Determine if model uses soft deletes.
at line 698
Client
getTypesenseClient()
Get the underlying Typesense client.
at line 706
protected mixed
getConfig(string $key, mixed $default = null)
Get a Scout configuration value.
at line 716
mixed
__call(string $method, array $parameters)
Dynamically proxy missing methods to the Typesense client instance.