AlgoliaEngine
class AlgoliaEngine extends Engine implements DeletesByFilter, 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.
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.
Get the import concurrency allowed for the given model.
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 AlgoliaEngine instance.
Build per-request identify headers for the current request.
Combine application and Builder filters without changing their precedence.
Build an equality filter for the given field and value.
Format the given value for use in an Algolia filter.
Delete all search indexes, optionally scoped by name prefix.
Update the index settings for the given index.
Configure the soft delete filter within the given settings.
Dynamically call the Algolia client instance.
Details
at line 62
void
update(Collection $models)
Update the given models in the search index.
at line 105
void
delete(Collection $models)
Remove the given models from the search index.
at line 124
mixed
search(Builder $builder)
Perform a search against the engine.
at line 134
mixed
paginate(Builder $builder, int $perPage, int $page)
Perform a paginated search against the engine.
at line 354
Collection
mapIds(mixed $results)
Pluck and return the primary keys of the given results.
at line 362
Collection
map(Builder $builder, mixed $results, Model $model)
Map the given results to instances of the given model.
at line 399
LazyCollection
lazyMap(Builder $builder, mixed $results, Model $model)
Map the given results to instances of the given model via a lazy collection.
at line 433
int
getTotalCount(mixed $results)
Get the total count from a raw result returned by the engine.
at line 441
void
flush(Model $model)
Flush all of the model's records from the engine.
at line 490
mixed
createIndex(string $name, array $options = [])
Create a search index.
at line 499
mixed
deleteIndex(string $name)
Delete a search index.
in
Engine at line 98
int
importConcurrency(Model $model, int $configured)
Get the import concurrency allowed for the given model.
in
Engine at line 111
Engine
setOperationRunner(EngineOperationRunner $runner, string $engineName)
Assign the operation runner to this engine.
The runner persists on a cached engine for the worker lifetime. Engines without observable operations retain no runner.
in
Engine at line 127
protected bool
hasObservableOperations()
Determine if this engine has operations worth observing.
in
Engine at line 137
void
runUpdate(Collection $models)
Update the given models through the operation runner.
in
Engine at line 167
void
runDelete(Collection $models)
Delete the given models through the operation runner.
in
Engine at line 215
mixed
runPaginate(Builder $builder, int $perPage, int $page)
Paginate through the operation runner.
in
Engine at line 235
void
runFlush(Model $model)
Flush the given model through the operation runner.
in
Engine at line 265
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 291
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 299
Collection
keys(Builder $builder)
Get the results of the query as a Collection of primary keys.
in
Engine at line 307
Collection
get(Builder $builder)
Get the results of the given query mapped onto models.
in
Engine at line 319
LazyCollection
cursor(Builder $builder)
Get a lazy collection for the given query mapped onto models.
at line 49
__construct(SearchClient $algolia, bool $softDelete = false, bool $identify = false)
Create a new AlgoliaEngine instance.
at line 145
protected mixed
performSearch(Builder $builder, array $options = [])
Perform the given search on the engine.
at line 194
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.
at line 222
protected string
filters(Builder $builder)
Get the filter expression for the query.
at line 288
protected string
combineFilters(string $applicationFilters, string $builderFilters)
Combine application and Builder filters without changing their precedence.
at line 304
protected string
equalityFilter(string $field, mixed $value)
Build an equality filter for the given field and value.
at line 318
protected string
formatFilterValue(mixed $value)
Format the given value for use in an Algolia filter.
at line 450
void
deleteByFilter(Builder $builder)
Delete every document matching the prepared Builder filters.
at line 514
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.
at line 537
void
updateIndexSettings(string $name, array $settings = [])
Update the index settings for the given index.
at line 548
array
configureSoftDeleteFilter(array $settings = [])
Configure the soft delete filter within the given settings.
at line 558
protected bool
usesSoftDelete(Model $model)
Determine if the given model uses soft deletes.
at line 566
mixed
__call(string $method, array $parameters)
Dynamically call the Algolia client instance.