PHP Class AlgoliaSearch\Client

You should instantiate a Client object with your ApplicationID, ApiKey and Hosts to start using Algolia Search API
Afficher le fichier Open project: algolia/algoliasearch-client-php Class Usage Examples

Protected Properties

Свойство Type Description
$caInfoPath string
$context ClientContext
$curlConstants array
$curlOptions array
$placesEnabled boolean

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
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.

Private Methods

Méthode Description
getPlacesIndex ( ) : PlacesIndex

Method Details

__construct() public méthode

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() public méthode

Release curl handle.
public __destruct ( )

addUserKey() public méthode

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)
Résultat mixed

batch() public méthode

Send a batch request targeting multiple indices.
public batch ( array $requests ) : mixed
$requests array an associative array defining the batch request body
Résultat mixed

buildQuery() public static méthode

public static buildQuery ( array $args ) : string
$args array
Résultat string

checkCurlOptions() protected méthode

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
Résultat array

copyIndex() public méthode

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).
Résultat mixed

deleteIndex() public méthode

Delete an index.
public deleteIndex ( string $indexName ) : mixed
$indexName string the name of index to delete
Résultat mixed an object containing a "deletedAt" attribute

deleteUserKey() public méthode

Delete an existing user key.
public deleteUserKey ( string $key ) : mixed
$key string
Résultat mixed

disableRateLimitForward() public méthode

Disable IP rate limit enabled with enableRateLimitForward() function.

doRequest() public méthode

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
Résultat mixed

enableRateLimitForward() public méthode

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() public static méthode

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
Résultat string

getCurlConstants() protected méthode

Get all php curl available options.
protected getCurlConstants ( ) : array
Résultat array

getLogs() public méthode

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
Résultat mixed

getUserKeyACL() public méthode

Get ACL of a user key.
public getUserKeyACL ( string $key ) : mixed
$key string
Résultat mixed

initIndex() public méthode

Get the index object initialized (no server call needed for initialization).
public initIndex ( string $indexName ) : Index
$indexName string the name of index
Résultat Index

initPlaces() public static méthode

public static initPlaces ( string $appId, string $apiKey, array $hostsArray = null, array $options = [] ) : PlacesIndex
$appId string
$apiKey string
$hostsArray array
$options array
Résultat PlacesIndex

invalidOptions() protected méthode

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() public méthode

Call isAlive.
public isAlive ( )

listIndexes() public méthode

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
Résultat mixed

listUserKeys() public méthode

List all existing user keys with their associated ACLs.
public listUserKeys ( ) : mixed
Résultat mixed

moveIndex() public méthode

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).
Résultat mixed

multipleQueries() public méthode

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
Résultat mixed

request() public méthode

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
Résultat mixed

setAlgoliaUserToken() public méthode

It's possible to use the following token to track users that have the same IP or to track users that use different devices.
See also: 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() public méthode

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() public méthode

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

setForwardedFor() public méthode

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.
See also: 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() public méthode

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)
Résultat mixed

Property Details

$caInfoPath protected_oe property

protected string $caInfoPath
Résultat string

$context protected_oe property

protected ClientContext,algoliasearch $context
Résultat ClientContext

$curlConstants protected_oe property

protected array $curlConstants
Résultat array

$curlOptions protected_oe property

protected array $curlOptions
Résultat array

$placesEnabled protected_oe property

protected bool $placesEnabled
Résultat boolean