class TypesenseEngine extends Engine

Typesense search engine implementation.

Provides full-text search using Typesense as the backend.

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
__construct(Client $typesense, int $maxTotalResults)

Create a new TypesenseEngine instance.

importDocuments(Collection $collectionIndex, array $documents, string|null $action = null)

Import the given documents into the index.

createImportSortingDataObject(array $document)

Create an import sorting data object for a given document.

array
deleteDocument(Collection $collectionIndex, mixed $modelId)

Delete a document from the index.

mixed
performSearch(Builder $builder, array $options = [])

Perform the given search on the engine.

array
performPaginatedSearch(Builder $builder)

Perform a paginated search on the engine.

array
buildSearchParameters(Builder $builder, int $page, int|null $perPage)

Build the search parameters for a given Scout query builder.

string
filters(Builder $builder)

Prepare the filters for a given search query.

array|string|int|float
parseFilterValue(array|string|bool|int|float $value)

Parse the given filter value.

string
parseWhereFilter(array|string|int|float $value, string $key)

Create a "where" filter string.

string
parseWhereInFilter(array $value, string $key)

Create a "where in" filter string.

string
parseWhereNotInFilter(array $value, string $key)

Create a "where not in" filter string.

string
parseOrderBy(array $orders)

Parse the order by fields for the query.

Collection
getOrCreateCollectionFromModel(Model $model, string|null $collectionName = null, bool $indexOperation = true)

Get collection from model or create new one.

bool
usesSoftDelete(Model $model)

Determine if model uses soft deletes.

Client
getTypesenseClient()

Get the underlying Typesense client.

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

Get a Scout configuration value.

mixed
__call(string $method, array $parameters)

Dynamically proxy missing methods to the Typesense client instance.

Details

at line 50
void update(Collection $models)

Update the given models in the search index.

Parameters

Collection $models

Return Value

void

Exceptions

TypesenseClientError

at line 140
void delete(Collection $models)

Remove the given models from the search index.

Parameters

Collection $models

Return Value

void

Exceptions

TypesenseClientError

Perform a search against the engine.

Parameters

Builder $builder

Return Value

mixed

Exceptions

TypesenseClientError

at line 200
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

Exceptions

TypesenseClientError

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 446
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 488
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 518
int getTotalCount(mixed $results)

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

Parameters

mixed $results

Return Value

int

at line 529
void flush(Model $model)

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

Parameters

Model $model

Return Value

void

Exceptions

TypesenseClientError

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

Create a search index.

Parameters

string $name
array $options

Return Value

mixed

Exceptions

NotSupportedException

at line 551
mixed deleteIndex(string $name)

Delete a search index.

Parameters

string $name

Return Value

mixed

Exceptions

TypesenseClientError
ObjectNotFound

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 38
__construct(Client $typesense, int $maxTotalResults)

Create a new TypesenseEngine instance.

Parameters

Client $typesense
int $maxTotalResults

at line 94
protected Collection importDocuments(Collection $collectionIndex, array $documents, string|null $action = null)

Import the given documents into the index.

Parameters

Collection $collectionIndex
array $documents
string|null $action

Return Value

Collection

Exceptions

TypesenseClientError

at line 122
protected stdClass createImportSortingDataObject(array $document)

Create an import sorting data object for a given document.

Parameters

array $document

Return Value

stdClass

at line 160
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.

Parameters

Collection $collectionIndex
mixed $modelId

Return Value

array

Exceptions

TypesenseClientError

at line 223
protected mixed performSearch(Builder $builder, array $options = [])

Perform the given search on the engine.

Parameters

Builder $builder
array $options

Return Value

mixed

Exceptions

TypesenseClientError

at line 250
protected array performPaginatedSearch(Builder $builder)

Perform a paginated search on the engine.

Parameters

Builder $builder

Return Value

array

Exceptions

TypesenseClientError

at line 294
array buildSearchParameters(Builder $builder, int $page, int|null $perPage)

Build the search parameters for a given Scout query builder.

Parameters

Builder $builder
int $page
int|null $perPage

Return Value

array

at line 341
protected string filters(Builder $builder)

Prepare the filters for a given search query.

Parameters

Builder $builder

Return Value

string

at line 369
protected array|string|int|float parseFilterValue(array|string|bool|int|float $value)

Parse the given filter value.

Parameters

array|string|bool|int|float $value

Return Value

array|string|int|float

at line 387
protected string parseWhereFilter(array|string|int|float $value, string $key)

Create a "where" filter string.

Parameters

array|string|int|float $value
string $key

Return Value

string

at line 399
protected string parseWhereInFilter(array $value, string $key)

Create a "where in" filter string.

Parameters

array $value
string $key

Return Value

string

at line 409
protected string parseWhereNotInFilter(array $value, string $key)

Create a "where not in" filter string.

Parameters

array $value
string $key

Return Value

string

at line 419
protected string parseOrderBy(array $orders)

Parse the order by fields for the query.

Parameters

array $orders

Return Value

string

at line 562
protected Collection getOrCreateCollectionFromModel(Model $model, string|null $collectionName = null, bool $indexOperation = true)

Get collection from model or create new one.

Parameters

Model $model
string|null $collectionName
bool $indexOperation

Return Value

Collection

Exceptions

TypesenseClientError

at line 614
protected bool usesSoftDelete(Model $model)

Determine if model uses soft deletes.

Parameters

Model $model

Return Value

bool

at line 622
Client getTypesenseClient()

Get the underlying Typesense client.

Return Value

Client

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

Get a Scout configuration value.

Parameters

string $key
mixed $default

Return Value

mixed

at line 640
mixed __call(string $method, array $parameters)

Dynamically proxy missing methods to the Typesense client instance.

Parameters

string $method
array $parameters

Return Value

mixed