PHP Class AlgoliaSearch\Index

ファイルを表示 Open project: algolia/algoliasearch-client-php Class Usage Examples

Public Properties

Property Type Description
$indexName string

Public Methods

Method Description
__call ( string $name, array $arguments ) : mixed
__construct ( ClientContext $context, Client $client, string $indexName ) Index initialization (You should not instantiate this yourself).
addObject ( array $content, string | null $objectID = null ) : mixed Add an object in this index.
addObjects ( array $objects, string $objectIDKey = 'objectID' ) : mixed Add several objects.
addUserKey ( array $obj, integer $validity, integer $maxQueriesPerIPPerHour, integer $maxHitsPerQuery ) : mixed Create a new user key associated to this index.
batch ( array $requests ) : mixed Send a batch request.
batchObjects ( array $objects, string $objectIDKey = 'objectID', string $objectActionKey = 'objectAction' ) : mixed Perform batch operation on several objects.
batchSynonyms ( $objects, boolean $forwardToReplicas = false, boolean $replaceExistingSynonyms = false ) : mixed
browseFrom ( string $query, array | null $params = null, $cursor = null ) : mixed
clearIndex ( ) : mixed This function deletes the index content. Settings and index specific API keys are kept untouched.
clearSynonyms ( boolean $forwardToReplicas = false ) : mixed
deleteByQuery ( string $query, array $args = [], boolean $waitLastCall = true ) : integer Delete all objects matching a query.
deleteObject ( integer | string $objectID ) : mixed Delete an object from the index.
deleteObjects ( array $objects ) : mixed Delete several objects.
deleteSynonym ( $objectID, $forwardToReplicas = false ) : mixed
deleteUserKey ( string $key ) : mixed Delete an existing user key associated to this index.
getObject ( $objectID, $attributesToRetrieve = null ) : mixed Get an object from this index.
getObjects ( array $objectIDs ) : mixed Get several objects from this index.
getSettings ( ) : mixed Get settings of this index.
getSynonym ( $objectID ) : mixed
getTaskStatus ( string $taskID ) : mixed get the status of a task on the server.
getUserKeyACL ( string $key ) : mixed Get ACL of a user key associated to this index.
listUserKeys ( ) : mixed List all existing user keys associated to this index with their associated ACLs.
partialUpdateObject ( array $partialObject, boolean $createIfNotExists = true ) : mixed Update partially an object (only update attributes passed in argument).
partialUpdateObjects ( array $objects, string $objectIDKey = 'objectID', boolean $createIfNotExists = true ) : mixed Partially Override the content of several objects.
saveObject ( array $object, string $objectIDKey = 'objectID' ) : mixed Override the content of object.
saveObjects ( array $objects, string $objectIDKey = 'objectID' ) : mixed Override the content of several objects.
saveSynonym ( $objectID, $content, boolean $forwardToReplicas = false ) : mixed
search ( string $query, mixed $args = null ) : mixed Search inside the index.
searchDisjunctiveFaceting ( string $query, array $disjunctive_facets, array $params = [], array $refinements = [] ) : mixed Perform a search with disjunctive facets generating as many queries as number of disjunctive facets.
searchFacet ( $facetName, $facetQuery, array $query = [] ) : mixed Perform a search inside facets.
searchSynonyms ( $query, array $synonymType = [], null $page = null, null $hitsPerPage = null ) : mixed
setSettings ( mixed $settings, boolean $forwardToReplicas = false ) : mixed Set settings for this index.
updateUserKey ( string $key, array $obj, integer $validity, integer $maxQueriesPerIPPerHour, integer $maxHitsPerQuery ) : mixed Update a user key associated to this index.
waitTask ( string $taskID, integer $timeBeforeRetry = 100 ) : mixed Wait the publication of a task on the server.

Private Methods

Method Description
buildBatch ( string $action, array $objects, string $withObjectID, string $objectIDKey = 'objectID' ) : array Build a batch request.
doBcBrowse ( integer $page, integer $hitsPerPage = 1000 ) : mixed Browse all index content.
doBrowse ( string $query, array | null $params = null ) : IndexBrowser

Method Details

__call() public method

public __call ( string $name, array $arguments ) : mixed
$name string
$arguments array
return mixed

__construct() public method

Index initialization (You should not instantiate this yourself).
public __construct ( ClientContext $context, Client $client, string $indexName )
$context ClientContext
$client Client
$indexName string

addObject() public method

Add an object in this index.
public addObject ( array $content, string | null $objectID = null ) : mixed
$content array contains the object to add inside the index. The object is represented by an associative array
$objectID string | null (optional) an objectID you want to attribute to this object (if the attribute already exist the old object will be overwrite)
return mixed

addObjects() public method

Add several objects.
public addObjects ( array $objects, string $objectIDKey = 'objectID' ) : mixed
$objects array contains an array of objects to add. If the object contains an objectID
$objectIDKey string
return mixed

addUserKey() public method

Create a new user key associated to this index.
public addUserKey ( array $obj, integer $validity, integer $maxQueriesPerIPPerHour, integer $maxHitsPerQuery ) : mixed
$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 NSString 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)
return mixed

batch() public method

Send a batch request.
public batch ( array $requests ) : mixed
$requests array an associative array defining the batch request body
return mixed

batchObjects() public method

Perform batch operation on several objects.
public batchObjects ( array $objects, string $objectIDKey = 'objectID', string $objectActionKey = 'objectAction' ) : mixed
$objects array contains an array of objects to update (each object must contains an objectID attribute)
$objectIDKey string the key in each object that contains the objectID
$objectActionKey string the key in each object that contains the action to perform (addObject, updateObject, deleteObject or partialUpdateObject)
return mixed

batchSynonyms() public method

public batchSynonyms ( $objects, boolean $forwardToReplicas = false, boolean $replaceExistingSynonyms = false ) : mixed
$objects
$forwardToReplicas boolean
$replaceExistingSynonyms boolean
return mixed

browseFrom() public method

public browseFrom ( string $query, array | null $params = null, $cursor = null ) : mixed
$query string
$params array | null
$cursor
return mixed

clearIndex() public method

This function deletes the index content. Settings and index specific API keys are kept untouched.
public clearIndex ( ) : mixed
return mixed

clearSynonyms() public method

public clearSynonyms ( boolean $forwardToReplicas = false ) : mixed
$forwardToReplicas boolean
return mixed

deleteByQuery() public method

Delete all objects matching a query.
public deleteByQuery ( string $query, array $args = [], boolean $waitLastCall = true ) : integer
$query string the query string
$args array the optional query parameters
$waitLastCall boolean /!\ Be safe with "waitLastCall" In really rare cases you can have the number of hits smaller than the hitsPerPage param if you trigger the timeout of the search, in that case you won't remove all the records
return integer the number of delete operations

deleteObject() public method

Delete an object from the index.
public deleteObject ( integer | string $objectID ) : mixed
$objectID integer | string the unique identifier of object to delete
return mixed

deleteObjects() public method

Delete several objects.
public deleteObjects ( array $objects ) : mixed
$objects array contains an array of objectIDs to delete. If the object contains an objectID
return mixed

deleteSynonym() public method

public deleteSynonym ( $objectID, $forwardToReplicas = false ) : mixed
$objectID
$forwardToReplicas
return mixed

deleteUserKey() public method

Delete an existing user key associated to this index.
public deleteUserKey ( string $key ) : mixed
$key string
return mixed

getObject() public method

Get an object from this index.
public getObject ( $objectID, $attributesToRetrieve = null ) : mixed
$objectID the unique identifier of the object to retrieve
$attributesToRetrieve (optional) if set, contains the list of attributes to retrieve as a string separated by ","
return mixed

getObjects() public method

Get several objects from this index.
public getObjects ( array $objectIDs ) : mixed
$objectIDs array the array of unique identifier of objects to retrieve
return mixed

getSettings() public method

Get settings of this index.
public getSettings ( ) : mixed
return mixed

getSynonym() public method

public getSynonym ( $objectID ) : mixed
$objectID
return mixed

getTaskStatus() public method

All server task are asynchronous and you can check with this method that the task is published or not.
public getTaskStatus ( string $taskID ) : mixed
$taskID string the id of the task returned by server
return mixed

getUserKeyACL() public method

Get ACL of a user key associated to this index.
public getUserKeyACL ( string $key ) : mixed
$key string
return mixed

listUserKeys() public method

List all existing user keys associated to this index with their associated ACLs.
public listUserKeys ( ) : mixed
return mixed

partialUpdateObject() public method

Update partially an object (only update attributes passed in argument).
public partialUpdateObject ( array $partialObject, boolean $createIfNotExists = true ) : mixed
$partialObject array contains the object attributes to override, the object must contains an objectID attribute
$createIfNotExists boolean
return mixed

partialUpdateObjects() public method

Partially Override the content of several objects.
public partialUpdateObjects ( array $objects, string $objectIDKey = 'objectID', boolean $createIfNotExists = true ) : mixed
$objects array contains an array of objects to update (each object must contains a objectID attribute)
$objectIDKey string
$createIfNotExists boolean
return mixed

saveObject() public method

Override the content of object.
public saveObject ( array $object, string $objectIDKey = 'objectID' ) : mixed
$object array contains the object to save, the object must contains an objectID attribute or attribute specified in $objectIDKey considered as objectID
$objectIDKey string
return mixed

saveObjects() public method

Override the content of several objects.
public saveObjects ( array $objects, string $objectIDKey = 'objectID' ) : mixed
$objects array contains an array of objects to update (each object must contains a objectID attribute)
$objectIDKey string
return mixed

saveSynonym() public method

public saveSynonym ( $objectID, $content, boolean $forwardToReplicas = false ) : mixed
$objectID
$content
$forwardToReplicas boolean
return mixed

searchDisjunctiveFaceting() public method

Perform a search with disjunctive facets generating as many queries as number of disjunctive facets.
public searchDisjunctiveFaceting ( string $query, array $disjunctive_facets, array $params = [], array $refinements = [] ) : mixed
$query string the query
$disjunctive_facets array the array of disjunctive facets
$params array a hash representing the regular query parameters
$refinements array a hash ("string" -> ["array", "of", "refined", "values"]) representing the current refinements ex: { "my_facet1" => ["my_value1", ["my_value2"], "my_disjunctive_facet1" => ["my_value1", "my_value2"] }
return mixed

searchFacet() public method

Perform a search inside facets.
public searchFacet ( $facetName, $facetQuery, array $query = [] ) : mixed
$facetName
$facetQuery
$query array
return mixed

searchSynonyms() public method

public searchSynonyms ( $query, array $synonymType = [], null $page = null, null $hitsPerPage = null ) : mixed
$query
$synonymType array
$page null
$hitsPerPage null
return mixed

setSettings() public method

Set settings for this index.
public setSettings ( mixed $settings, boolean $forwardToReplicas = false ) : mixed
$settings mixed the settings object that can contains : - minWordSizefor1Typo: (integer) the minimum number of characters to accept one typo (default = 3). - minWordSizefor2Typos: (integer) the minimum number of characters to accept two typos (default = 7). - hitsPerPage: (integer) the number of hits per page (default = 10). - attributesToRetrieve: (array of strings) default list of attributes to retrieve in objects. If set to null, all attributes are retrieved. - attributesToHighlight: (array of strings) default list of attributes to highlight. If set to null, all indexed attributes are highlighted. - attributesToSnippet**: (array of strings) default list of attributes to snippet alongside the number of words to return (syntax is attributeName:nbWords). By default no snippet is computed. If set to null, no snippet is computed. - searchableAttributes (formerly named attributesToIndex): (array of strings) the list of fields you want to index. If set to null, all textual and numerical attributes of your objects are indexed, but you should update it to get optimal results. This parameter has two important uses: - Limit the attributes to index: For example if you store a binary image in base64, you want to store it and be able to retrieve it but you don't want to search in the base64 string. - Control part of the ranking*: (see the ranking parameter for full explanation) Matches in attributes at the beginning of the list will be considered more important than matches in attributes further down the list. In one attribute, matching text at the beginning of the attribute will be considered more important than text after, you can disable this behavior if you add your attribute inside `unordered(AttributeName)`, for example searchableAttributes: ["title", "unordered(text)"]. - attributesForFaceting: (array of strings) The list of fields you want to use for faceting. All strings in the attribute selected for faceting are extracted and added as a facet. If set to null, no attribute is used for faceting. - attributeForDistinct: (string) The attribute name used for the Distinct feature. This feature is similar to the SQL "distinct" keyword: when enabled in query with the distinct=1 parameter, all hits containing a duplicate value for this attribute are removed from results. For example, if the chosen attribute is show_name and several hits have the same value for show_name, then only the best one is kept and others are removed. - ranking: (array of strings) controls the way results are sorted. We have six available criteria: - typo: sort according to number of typos, - geo: sort according to decreassing distance when performing a geo-location based search, - proximity: sort according to the proximity of query words in hits, - attribute: sort according to the order of attributes defined by searchableAttributes, - exact: - if the user query contains one word: sort objects having an attribute that is exactly the query word before others. For example if you search for the "V" TV show, you want to find it with the "V" query and avoid to have all popular TV show starting by the v letter before it. - if the user query contains multiple words: sort according to the number of words that matched exactly (and not as a prefix). - custom: sort according to a user defined formula set in **customRanking** attribute. The standard order is ["typo", "geo", "proximity", "attribute", "exact", "custom"] - customRanking: (array of strings) lets you specify part of the ranking. The syntax of this condition is an array of strings containing attributes prefixed by asc (ascending order) or desc (descending order) operator. For example `"customRanking" => ["desc(population)", "asc(name)"]` - queryType: Select how the query words are interpreted, it can be one of the following value: - prefixAll: all query words are interpreted as prefixes, - prefixLast: only the last word is interpreted as a prefix (default behavior), - prefixNone: no query word is interpreted as a prefix. This option is not recommended. - highlightPreTag: (string) Specify the string that is inserted before the highlighted parts in the query result (default to ""). - highlightPostTag: (string) Specify the string that is inserted after the highlighted parts in the query result (default to ""). - optionalWords: (array of strings) Specify a list of words that should be considered as optional when found in the query.
$forwardToReplicas boolean
return mixed

updateUserKey() public method

Update a user key associated to this index.
public updateUserKey ( string $key, array $obj, integer $validity, integer $maxQueriesPerIPPerHour, integer $maxHitsPerQuery ) : 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 NSString 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)
return mixed

waitTask() public method

All server task are asynchronous and you can check with this method that the task is published.
public waitTask ( string $taskID, integer $timeBeforeRetry = 100 ) : mixed
$taskID string the id of the task returned by server
$timeBeforeRetry integer the time in milliseconds before retry (default = 100ms)
return mixed

Property Details

$indexName public_oe property

public string $indexName
return string