PHP Класс AlgoliaSearch\Client

You should instantiate a Client object with your ApplicationID, ApiKey and Hosts to start using Algolia Search API
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$caInfoPath string
$context ClientContext
$curlConstants array
$curlOptions array
$placesEnabled boolean

Открытые методы

Метод Описание
__construct ( string $applicationID, string $apiKey, array | null $hostsArray = null, array $options = [] ) Algolia Search initialization.
__destruct ( ) Release curl handle.
addUserKey ( array $obj, integer $validity, integer $maxQueriesPerIPPerHour, integer $maxHitsPerQuery, array | null $indexes = null ) : mixed Create a new user key.
batch ( array $requests ) : mixed Send a batch request targeting multiple indices.
buildQuery ( array $args ) : string
copyIndex ( string $srcIndexName, string $dstIndexName ) : mixed Copy an existing index.
deleteIndex ( string $indexName ) : mixed Delete an index.
deleteUserKey ( string $key ) : mixed Delete an existing user key.
disableRateLimitForward ( ) Disable IP rate limit enabled with enableRateLimitForward() function.
doRequest ( ClientContext $context, string $method, string $host, string $path, array $params, array $data, integer $connectTimeout, integer $readTimeout ) : mixed
enableRateLimitForward ( string $adminAPIKey, string $endUserIP, string $rateLimitAPIKey ) Allow to use IP rate limit when you have a proxy between end-user and Algolia.
generateSecuredApiKey ( string $privateApiKey, mixed $query, string | null $userToken = null ) : string Generate a secured and public API Key from a list of query parameters and an optional user token identifying the current user.
getLogs ( integer $offset, integer $length = 10, mixed $type = 'all' ) : mixed Return last logs entries.
getUserKeyACL ( string $key ) : mixed Get ACL of a user key.
initIndex ( string $indexName ) : Index Get the index object initialized (no server call needed for initialization).
initPlaces ( string $appId, string $apiKey, array $hostsArray = null, array $options = [] ) : PlacesIndex
isAlive ( ) Call isAlive.
listIndexes ( ) : mixed List all existing indexes return an object in the form: array( "items" => array( array("name" => "contacts", "createdAt" => "2013-01-18T15:33:13.556Z"), array("name" => "notes", "createdAt" => "2013-01-18T15:33:13.556Z") ) ).
listUserKeys ( ) : mixed List all existing user keys with their associated ACLs.
moveIndex ( string $srcIndexName, string $dstIndexName ) : mixed Move an existing index.
multipleQueries ( array $queries, string $indexNameKey = 'indexName', string $strategy = 'none' ) : mixed This method allows to query multiple indexes with one API call.
request ( ClientContext $context, string $method, string $path, array $params, array $data, array $hostsArray, integer $connectTimeout, integer $readTimeout ) : mixed
setAlgoliaUserToken ( string $token ) It's possible to use the following token to track users that have the same IP or to track users that use different devices.
setConnectTimeout ( integer $connectTimeout, integer $timeout = 30, integer $searchTimeout = 5 ) Change the default connect timeout of 2s to a custom value (only useful if your server has a very slow connectivity to Algolia backend).
setExtraHeader ( string $key, string $value ) Allow to set custom headers.
setForwardedFor ( string $ip ) The aggregation of the queries to retrieve the latest query uses the IP or the user token to work efficiently.
updateUserKey ( string $key, array $obj, integer $validity, integer $maxQueriesPerIPPerHour, integer $maxHitsPerQuery, array | null $indexes = null ) : mixed Update a user key.

Защищенные методы

Метод Описание
checkCurlOptions ( array $curlOptions ) : array Checks if curl option passed are valid curl options.
getCurlConstants ( ) : array Get all php curl available options.
invalidOptions ( array $curlOptions = [], string $errorMsg = '' ) throw clear Exception when bad curl option is set.

Приватные методы

Метод Описание
getPlacesIndex ( ) : PlacesIndex

Описание методов

__construct() публичный Метод

Algolia Search initialization.
public __construct ( string $applicationID, string $apiKey, array | null $hostsArray = null, array $options = [] )
$applicationID string the application ID you have in your admin interface
$apiKey string a valid API key for the service
$hostsArray array | null the list of hosts that you have received for the service
$options array

__destruct() публичный Метод

Release curl handle.
public __destruct ( )

addUserKey() публичный Метод

Create a new user key.
public addUserKey ( array $obj, integer $validity, integer $maxQueriesPerIPPerHour, integer $maxHitsPerQuery, array | null $indexes = null ) : mixed
$obj array can be two different parameters: The list of parameters for this key. Defined by an array that can contain the following values: - acl: array of string - indices: array of string - validity: int - referers: array of string - description: string - maxHitsPerQuery: integer - queryParameters: string - maxQueriesPerIPPerHour: integer Or the list of ACL for this key. Defined by an array of string that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
$validity integer the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
$maxQueriesPerIPPerHour integer Specify the maximum number of API calls allowed from an IP address per hour. Defaults to 0 (no rate limit).
$maxHitsPerQuery integer Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited)
$indexes array | null Specify the list of indices to target (null means all)
Результат mixed

batch() публичный Метод

Send a batch request targeting multiple indices.
public batch ( array $requests ) : mixed
$requests array an associative array defining the batch request body
Результат mixed

buildQuery() публичный статический Метод

public static buildQuery ( array $args ) : string
$args array
Результат string

checkCurlOptions() защищенный Метод

Checks if curl option passed are valid curl options.
protected checkCurlOptions ( array $curlOptions ) : array
$curlOptions array must be array but no type required while first test throw clear Exception
Результат array

copyIndex() публичный Метод

Copy an existing index.
public copyIndex ( string $srcIndexName, string $dstIndexName ) : mixed
$srcIndexName string the name of index to copy.
$dstIndexName string the new index name that will contains a copy of srcIndexName (destination will be overwritten if it already exist).
Результат mixed

deleteIndex() публичный Метод

Delete an index.
public deleteIndex ( string $indexName ) : mixed
$indexName string the name of index to delete
Результат mixed an object containing a "deletedAt" attribute

deleteUserKey() публичный Метод

Delete an existing user key.
public deleteUserKey ( string $key ) : mixed
$key string
Результат mixed

disableRateLimitForward() публичный Метод

Disable IP rate limit enabled with enableRateLimitForward() function.

doRequest() публичный Метод

public doRequest ( ClientContext $context, string $method, string $host, string $path, array $params, array $data, integer $connectTimeout, integer $readTimeout ) : mixed
$context ClientContext
$method string
$host string
$path string
$params array
$data array
$connectTimeout integer
$readTimeout integer
Результат mixed

enableRateLimitForward() публичный Метод

This option will set the X-Forwarded-For HTTP header with the client IP and the X-Forwarded-API-Key with the API Key having rate limits.
public enableRateLimitForward ( string $adminAPIKey, string $endUserIP, string $rateLimitAPIKey )
$adminAPIKey string the admin API Key you can find in your dashboard
$endUserIP string the end user IP (you can use both IPV4 or IPV6 syntax)
$rateLimitAPIKey string the API key on which you have a rate limit

generateSecuredApiKey() публичный статический Метод

Generate a secured and public API Key from a list of query parameters and an optional user token identifying the current user.
public static generateSecuredApiKey ( string $privateApiKey, mixed $query, string | null $userToken = null ) : string
$privateApiKey string your private API Key
$query mixed the list of query parameters applied to the query (used as security)
$userToken string | null an optional token identifying the current user
Результат string

getCurlConstants() защищенный Метод

Get all php curl available options.
protected getCurlConstants ( ) : array
Результат array

getLogs() публичный Метод

Return last logs entries.
public getLogs ( integer $offset, integer $length = 10, mixed $type = 'all' ) : mixed
$offset integer Specify the first entry to retrieve (0-based, 0 is the most recent log entry).
$length integer Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000.
$type mixed
Результат mixed

getUserKeyACL() публичный Метод

Get ACL of a user key.
public getUserKeyACL ( string $key ) : mixed
$key string
Результат mixed

initIndex() публичный Метод

Get the index object initialized (no server call needed for initialization).
public initIndex ( string $indexName ) : Index
$indexName string the name of index
Результат Index

initPlaces() публичный статический Метод

public static initPlaces ( string $appId, string $apiKey, array $hostsArray = null, array $options = [] ) : PlacesIndex
$appId string
$apiKey string
$hostsArray array
$options array
Результат PlacesIndex

invalidOptions() защищенный Метод

throw clear Exception when bad curl option is set.
protected invalidOptions ( array $curlOptions = [], string $errorMsg = '' )
$curlOptions array
$errorMsg string add specific message for disambiguation

isAlive() публичный Метод

Call isAlive.
public isAlive ( )

listIndexes() публичный Метод

List all existing indexes return an object in the form: array( "items" => array( array("name" => "contacts", "createdAt" => "2013-01-18T15:33:13.556Z"), array("name" => "notes", "createdAt" => "2013-01-18T15:33:13.556Z") ) ).
public listIndexes ( ) : mixed
Результат mixed

listUserKeys() публичный Метод

List all existing user keys with their associated ACLs.
public listUserKeys ( ) : mixed
Результат mixed

moveIndex() публичный Метод

Move an existing index.
public moveIndex ( string $srcIndexName, string $dstIndexName ) : mixed
$srcIndexName string the name of index to copy.
$dstIndexName string the new index name that will contains a copy of srcIndexName (destination will be overwritten if it already exist).
Результат mixed

multipleQueries() публичный Метод

This method allows to query multiple indexes with one API call.
public multipleQueries ( array $queries, string $indexNameKey = 'indexName', string $strategy = 'none' ) : mixed
$queries array
$indexNameKey string
$strategy string
Результат mixed

request() публичный Метод

public request ( ClientContext $context, string $method, string $path, array $params, array $data, array $hostsArray, integer $connectTimeout, integer $readTimeout ) : mixed
$context ClientContext
$method string
$path string
$params array
$data array
$hostsArray array
$connectTimeout integer
$readTimeout integer
Результат mixed

setAlgoliaUserToken() публичный Метод

It's possible to use the following token to track users that have the same IP or to track users that use different devices.
См. также: https://www.algolia.com/doc/faq/analytics/will-the-analytics-still-work-if-i-perform-the-search-through-my-backend
public setAlgoliaUserToken ( string $token )
$token string

setConnectTimeout() публичный Метод

Change the default connect timeout of 2s to a custom value (only useful if your server has a very slow connectivity to Algolia backend).
public setConnectTimeout ( integer $connectTimeout, integer $timeout = 30, integer $searchTimeout = 5 )
$connectTimeout integer the connection timeout
$timeout integer the read timeout for the query
$searchTimeout integer the read timeout used for search queries only

setExtraHeader() публичный Метод

Allow to set custom headers.
public setExtraHeader ( string $key, string $value )
$key string
$value string

setForwardedFor() публичный Метод

If the queries are made from your backend server, the IP will be the same for all of the queries. We're supporting the following HTTP header to forward the IP of your end-user to the engine, you just need to set it for each query.
См. также: https://www.algolia.com/doc/faq/analytics/will-the-analytics-still-work-if-i-perform-the-search-through-my-backend
public setForwardedFor ( string $ip )
$ip string

updateUserKey() публичный Метод

Update a user key.
public updateUserKey ( string $key, array $obj, integer $validity, integer $maxQueriesPerIPPerHour, integer $maxHitsPerQuery, array | null $indexes = null ) : mixed
$key string
$obj array can be two different parameters: The list of parameters for this key. Defined by a array that can contains the following values: - acl: array of string - indices: array of string - validity: int - referers: array of string - description: string - maxHitsPerQuery: integer - queryParameters: string - maxQueriesPerIPPerHour: integer Or the list of ACL for this key. Defined by an array of string that can contains the following values: - search: allow to search (https and http) - addObject: allows to add/update an object in the index (https only) - deleteObject : allows to delete an existing object (https only) - deleteIndex : allows to delete index content (https only) - settings : allows to get index settings (https only) - editSettings : allows to change index settings (https only)
$validity integer the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
$maxQueriesPerIPPerHour integer Specify the maximum number of API calls allowed from an IP address per hour. Defaults to 0 (no rate limit).
$maxHitsPerQuery integer Specify the maximum number of hits this API key can retrieve in one call. Defaults to 0 (unlimited)
$indexes array | null Specify the list of indices to target (null means all)
Результат mixed

Описание свойств

$caInfoPath защищенное свойство

protected string $caInfoPath
Результат string

$context защищенное свойство

protected ClientContext,algoliasearch $context
Результат ClientContext

$curlConstants защищенное свойство

protected array $curlConstants
Результат array

$curlOptions защищенное свойство

protected array $curlOptions
Результат array

$placesEnabled защищенное свойство

protected bool $placesEnabled
Результат boolean