class AlgoliaEngine extends Engine implements UpdatesIndexSettings

Algolia search engine implementation (v4 client).

Uses the Algolia\AlgoliaSearch\Api\SearchClient (v4) flat API. The v3 split-concrete-class layout from Laravel is collapsed into this single class because Hypervel only supports Algolia v4.

Identify headers (X-Forwarded-For, X-Algolia-UserToken) are computed per request and passed as per-call request options rather than baked into default client headers at construction time. This is the deliberate divergence from Laravel's EngineManager::defaultAlgoliaHeaders() which cannot work correctly under a persistent-worker model where the engine instance is cached across requests.

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(SearchClient $algolia, bool $softDelete = false, bool $identify = false)

Create a new AlgoliaEngine instance.

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

Perform the given search on the engine.

array
identifyHeaders()

Build per-request identify headers for the current request.

array
filters(Builder $builder)

Get the filter array for the query.

array
deleteAllIndexes(string|null $prefix = null)

Delete all search indexes, optionally scoped by name prefix.

void
updateIndexSettings(string $name, array $settings = [])

Update the index settings for the given index.

array
configureSoftDeleteFilter(array $settings = [])

Configure the soft delete filter within the given settings.

bool
usesSoftDelete(Model $model)

Determine if the given model uses soft deletes.

mixed
__call(string $method, array $parameters)

Dynamically call the Algolia client instance.

Details

at line 53
void update(Collection $models)

Update the given models in the search index.

Parameters

Collection $models

Return Value

void

Exceptions

AlgoliaException

at line 95
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 125
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 241
Collection mapIds(mixed $results)

Pluck and return the primary keys of the given results.

Parameters

mixed $results

Return Value

Collection

at line 251
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 290
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 325
int getTotalCount(mixed $results)

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

Parameters

mixed $results

Return Value

int

at line 335
void flush(Model $model)

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

Parameters

Model $model

Return Value

void

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

Create a search index.

Parameters

string $name
array $options

Return Value

mixed

Exceptions

NotSupportedException

at line 353
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 40
__construct(SearchClient $algolia, bool $softDelete = false, bool $identify = false)

Create a new AlgoliaEngine instance.

Parameters

SearchClient $algolia
bool $softDelete
bool $identify

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

Perform the given search on the engine.

Parameters

Builder $builder
array $options

Return Value

mixed

at line 179
protected array identifyHeaders()

Build per-request identify headers for the current request.

Reads the current coroutine-local request directly from RequestContext rather than via the request() helper. Matches the pattern used by CookieJar and other Hypervel code that needs request state without depending on HttpServiceProvider being registered. Returns an empty array when no request is in context (e.g. CLI, queue jobs), the IP is missing or private/reserved, or no authenticated user is present.

Return Value

array

at line 209
protected array filters(Builder $builder)

Get the filter array for the query.

Parameters

Builder $builder

Return Value

array

at line 368
array deleteAllIndexes(string|null $prefix = null)

Delete all search indexes, optionally scoped by name prefix.

When $prefix is non-empty, only indexes whose name starts with $prefix are deleted. When $prefix is null (or empty string, which str_starts_with matches against every string), every index in the Algolia application is deleted.

Parameters

string|null $prefix

Return Value

array

Task/response objects from each deleteIndex call

at line 391
void updateIndexSettings(string $name, array $settings = [])

Update the index settings for the given index.

Parameters

string $name
array $settings

Return Value

void

at line 402
array configureSoftDeleteFilter(array $settings = [])

Configure the soft delete filter within the given settings.

Parameters

array $settings

Return Value

array

at line 412
protected bool usesSoftDelete(Model $model)

Determine if the given model uses soft deletes.

Parameters

Model $model

Return Value

bool

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

Dynamically call the Algolia client instance.

Parameters

string $method
array $parameters

Return Value

mixed