repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
apisearch-io/php-client
Repository/TransformableRepository.php
TransformableRepository.deleteObject
public function deleteObject($object) { $itemUUID = $this ->transformer ->toItemUUID($object); if ($itemUUID instanceof ItemUUID) { $this->deleteItem($itemUUID); } }
php
public function deleteObject($object) { $itemUUID = $this ->transformer ->toItemUUID($object); if ($itemUUID instanceof ItemUUID) { $this->deleteItem($itemUUID); } }
[ "public", "function", "deleteObject", "(", "$", "object", ")", "{", "$", "itemUUID", "=", "$", "this", "->", "transformer", "->", "toItemUUID", "(", "$", "object", ")", ";", "if", "(", "$", "itemUUID", "instanceof", "ItemUUID", ")", "{", "$", "this", "->", "deleteItem", "(", "$", "itemUUID", ")", ";", "}", "}" ]
Delete item document by uuid. @param mixed $object
[ "Delete", "item", "document", "by", "uuid", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/TransformableRepository.php#L208-L217
apisearch-io/php-client
Exception/InvalidTokenException.php
InvalidTokenException.createInvalidTokenMaxHitsPerQuery
public static function createInvalidTokenMaxHitsPerQuery( string $tokenReference, int $maxHitsPerQuery ): self { return new self(sprintf('Token %s not valid. Max %d hits allowed', $tokenReference, $maxHitsPerQuery)); }
php
public static function createInvalidTokenMaxHitsPerQuery( string $tokenReference, int $maxHitsPerQuery ): self { return new self(sprintf('Token %s not valid. Max %d hits allowed', $tokenReference, $maxHitsPerQuery)); }
[ "public", "static", "function", "createInvalidTokenMaxHitsPerQuery", "(", "string", "$", "tokenReference", ",", "int", "$", "maxHitsPerQuery", ")", ":", "self", "{", "return", "new", "self", "(", "sprintf", "(", "'Token %s not valid. Max %d hits allowed'", ",", "$", "tokenReference", ",", "$", "maxHitsPerQuery", ")", ")", ";", "}" ]
Throw an invalid key exception. @param string $tokenReference @param int $maxHitsPerQuery @return InvalidTokenException
[ "Throw", "an", "invalid", "key", "exception", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exception/InvalidTokenException.php#L53-L58
apisearch-io/php-client
Model/Item.php
Item.create
public static function create( ItemUUID $uuid, array $metadata = [], array $indexedMetadata = [], array $searchableMetadata = [], array $exactMatchingMetadata = [], array $suggest = [] ) { return new self( $uuid, null, $metadata, $indexedMetadata, $searchableMetadata, $exactMatchingMetadata, $suggest ); }
php
public static function create( ItemUUID $uuid, array $metadata = [], array $indexedMetadata = [], array $searchableMetadata = [], array $exactMatchingMetadata = [], array $suggest = [] ) { return new self( $uuid, null, $metadata, $indexedMetadata, $searchableMetadata, $exactMatchingMetadata, $suggest ); }
[ "public", "static", "function", "create", "(", "ItemUUID", "$", "uuid", ",", "array", "$", "metadata", "=", "[", "]", ",", "array", "$", "indexedMetadata", "=", "[", "]", ",", "array", "$", "searchableMetadata", "=", "[", "]", ",", "array", "$", "exactMatchingMetadata", "=", "[", "]", ",", "array", "$", "suggest", "=", "[", "]", ")", "{", "return", "new", "self", "(", "$", "uuid", ",", "null", ",", "$", "metadata", ",", "$", "indexedMetadata", ",", "$", "searchableMetadata", ",", "$", "exactMatchingMetadata", ",", "$", "suggest", ")", ";", "}" ]
Create. @param ItemUUID $uuid @param array $metadata @param array $indexedMetadata @param array $searchableMetadata @param array $exactMatchingMetadata @param array $suggest @return Item
[ "Create", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Item.php#L143-L160
apisearch-io/php-client
Model/Item.php
Item.createLocated
public static function createLocated( ItemUUID $uuid, Coordinate $coordinate, array $metadata = [], array $indexedMetadata = [], array $searchableMetadata = [], array $exactMatchingMetadata = [], array $suggest = [] ) { return new self( $uuid, $coordinate, $metadata, $indexedMetadata, $searchableMetadata, $exactMatchingMetadata, $suggest ); }
php
public static function createLocated( ItemUUID $uuid, Coordinate $coordinate, array $metadata = [], array $indexedMetadata = [], array $searchableMetadata = [], array $exactMatchingMetadata = [], array $suggest = [] ) { return new self( $uuid, $coordinate, $metadata, $indexedMetadata, $searchableMetadata, $exactMatchingMetadata, $suggest ); }
[ "public", "static", "function", "createLocated", "(", "ItemUUID", "$", "uuid", ",", "Coordinate", "$", "coordinate", ",", "array", "$", "metadata", "=", "[", "]", ",", "array", "$", "indexedMetadata", "=", "[", "]", ",", "array", "$", "searchableMetadata", "=", "[", "]", ",", "array", "$", "exactMatchingMetadata", "=", "[", "]", ",", "array", "$", "suggest", "=", "[", "]", ")", "{", "return", "new", "self", "(", "$", "uuid", ",", "$", "coordinate", ",", "$", "metadata", ",", "$", "indexedMetadata", ",", "$", "searchableMetadata", ",", "$", "exactMatchingMetadata", ",", "$", "suggest", ")", ";", "}" ]
Create located. @param ItemUUID $uuid @param Coordinate $coordinate @param array $metadata @param array $indexedMetadata @param array $searchableMetadata @param array $exactMatchingMetadata @param array $suggest @return Item
[ "Create", "located", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Item.php#L175-L193
apisearch-io/php-client
Model/Item.php
Item.getHighlight
public function getHighlight(string $fieldName): ? string { return isset($this->highlights[$fieldName]) ? ((string) $this->highlights[$fieldName]) : null; }
php
public function getHighlight(string $fieldName): ? string { return isset($this->highlights[$fieldName]) ? ((string) $this->highlights[$fieldName]) : null; }
[ "public", "function", "getHighlight", "(", "string", "$", "fieldName", ")", ":", "?", "string", "{", "return", "isset", "(", "$", "this", "->", "highlights", "[", "$", "fieldName", "]", ")", "?", "(", "(", "string", ")", "$", "this", "->", "highlights", "[", "$", "fieldName", "]", ")", ":", "null", ";", "}" ]
Get Highlights. @param string $fieldName @return string|null
[ "Get", "Highlights", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Item.php#L433-L438
apisearch-io/php-client
Model/Item.php
Item.toArray
public function toArray(): array { return array_filter([ 'uuid' => $this->uuid->toArray(), 'coordinate' => $this->coordinate instanceof Coordinate ? $this->coordinate->toArray() : null, 'distance' => $this->distance, 'metadata' => $this->metadata, 'indexed_metadata' => $this->indexedMetadata, 'searchable_metadata' => $this->searchableMetadata, 'exact_matching_metadata' => $this->exactMatchingMetadata, 'suggest' => $this->suggest, 'highlights' => $this->highlights, 'is_promoted' => !$this->promoted ? null : true, 'score' => $this->score, ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
php
public function toArray(): array { return array_filter([ 'uuid' => $this->uuid->toArray(), 'coordinate' => $this->coordinate instanceof Coordinate ? $this->coordinate->toArray() : null, 'distance' => $this->distance, 'metadata' => $this->metadata, 'indexed_metadata' => $this->indexedMetadata, 'searchable_metadata' => $this->searchableMetadata, 'exact_matching_metadata' => $this->exactMatchingMetadata, 'suggest' => $this->suggest, 'highlights' => $this->highlights, 'is_promoted' => !$this->promoted ? null : true, 'score' => $this->score, ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "array_filter", "(", "[", "'uuid'", "=>", "$", "this", "->", "uuid", "->", "toArray", "(", ")", ",", "'coordinate'", "=>", "$", "this", "->", "coordinate", "instanceof", "Coordinate", "?", "$", "this", "->", "coordinate", "->", "toArray", "(", ")", ":", "null", ",", "'distance'", "=>", "$", "this", "->", "distance", ",", "'metadata'", "=>", "$", "this", "->", "metadata", ",", "'indexed_metadata'", "=>", "$", "this", "->", "indexedMetadata", ",", "'searchable_metadata'", "=>", "$", "this", "->", "searchableMetadata", ",", "'exact_matching_metadata'", "=>", "$", "this", "->", "exactMatchingMetadata", ",", "'suggest'", "=>", "$", "this", "->", "suggest", ",", "'highlights'", "=>", "$", "this", "->", "highlights", ",", "'is_promoted'", "=>", "!", "$", "this", "->", "promoted", "?", "null", ":", "true", ",", "'score'", "=>", "$", "this", "->", "score", ",", "]", ",", "function", "(", "$", "element", ")", "{", "return", "!", "(", "is_null", "(", "$", "element", ")", "||", "(", "is_array", "(", "$", "element", ")", "&&", "empty", "(", "$", "element", ")", ")", ")", ";", "}", ")", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Item.php#L497-L520
apisearch-io/php-client
Model/Item.php
Item.createFromArray
public static function createFromArray(array $array): self { if ( !isset($array['uuid']) || !is_array($array['uuid']) ) { throw InvalidFormatException::itemUUIDRepresentationNotValid($array['uuid'] ?? []); } if ( isset($array['coordinate']) && !is_array($array['coordinate']) ) { throw InvalidFormatException::coordinateFormatNotValid(); } $item = isset($array['coordinate']) ? self::createLocated( ItemUUID::createFromArray($array['uuid']), Coordinate::createFromArray($array['coordinate']), $array['metadata'] ?? [], $array['indexed_metadata'] ?? [], $array['searchable_metadata'] ?? [], $array['exact_matching_metadata'] ?? [], $array['suggest'] ?? [] ) : self::create( ItemUUID::createFromArray($array['uuid']), $array['metadata'] ?? [], $array['indexed_metadata'] ?? [], $array['searchable_metadata'] ?? [], $array['exact_matching_metadata'] ?? [], $array['suggest'] ?? [] ); if (isset($array['distance'])) { $item->distance = (float) $array['distance']; } if (isset($array['highlights'])) { $item->highlights = $array['highlights']; } if (isset($array['is_promoted']) && true === $array['is_promoted']) { $item->setPromoted(); } if (isset($array['score']) && !is_null($array['score'])) { $item->setScore((float) $array['score']); } return $item; }
php
public static function createFromArray(array $array): self { if ( !isset($array['uuid']) || !is_array($array['uuid']) ) { throw InvalidFormatException::itemUUIDRepresentationNotValid($array['uuid'] ?? []); } if ( isset($array['coordinate']) && !is_array($array['coordinate']) ) { throw InvalidFormatException::coordinateFormatNotValid(); } $item = isset($array['coordinate']) ? self::createLocated( ItemUUID::createFromArray($array['uuid']), Coordinate::createFromArray($array['coordinate']), $array['metadata'] ?? [], $array['indexed_metadata'] ?? [], $array['searchable_metadata'] ?? [], $array['exact_matching_metadata'] ?? [], $array['suggest'] ?? [] ) : self::create( ItemUUID::createFromArray($array['uuid']), $array['metadata'] ?? [], $array['indexed_metadata'] ?? [], $array['searchable_metadata'] ?? [], $array['exact_matching_metadata'] ?? [], $array['suggest'] ?? [] ); if (isset($array['distance'])) { $item->distance = (float) $array['distance']; } if (isset($array['highlights'])) { $item->highlights = $array['highlights']; } if (isset($array['is_promoted']) && true === $array['is_promoted']) { $item->setPromoted(); } if (isset($array['score']) && !is_null($array['score'])) { $item->setScore((float) $array['score']); } return $item; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", ":", "self", "{", "if", "(", "!", "isset", "(", "$", "array", "[", "'uuid'", "]", ")", "||", "!", "is_array", "(", "$", "array", "[", "'uuid'", "]", ")", ")", "{", "throw", "InvalidFormatException", "::", "itemUUIDRepresentationNotValid", "(", "$", "array", "[", "'uuid'", "]", "??", "[", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "array", "[", "'coordinate'", "]", ")", "&&", "!", "is_array", "(", "$", "array", "[", "'coordinate'", "]", ")", ")", "{", "throw", "InvalidFormatException", "::", "coordinateFormatNotValid", "(", ")", ";", "}", "$", "item", "=", "isset", "(", "$", "array", "[", "'coordinate'", "]", ")", "?", "self", "::", "createLocated", "(", "ItemUUID", "::", "createFromArray", "(", "$", "array", "[", "'uuid'", "]", ")", ",", "Coordinate", "::", "createFromArray", "(", "$", "array", "[", "'coordinate'", "]", ")", ",", "$", "array", "[", "'metadata'", "]", "??", "[", "]", ",", "$", "array", "[", "'indexed_metadata'", "]", "??", "[", "]", ",", "$", "array", "[", "'searchable_metadata'", "]", "??", "[", "]", ",", "$", "array", "[", "'exact_matching_metadata'", "]", "??", "[", "]", ",", "$", "array", "[", "'suggest'", "]", "??", "[", "]", ")", ":", "self", "::", "create", "(", "ItemUUID", "::", "createFromArray", "(", "$", "array", "[", "'uuid'", "]", ")", ",", "$", "array", "[", "'metadata'", "]", "??", "[", "]", ",", "$", "array", "[", "'indexed_metadata'", "]", "??", "[", "]", ",", "$", "array", "[", "'searchable_metadata'", "]", "??", "[", "]", ",", "$", "array", "[", "'exact_matching_metadata'", "]", "??", "[", "]", ",", "$", "array", "[", "'suggest'", "]", "??", "[", "]", ")", ";", "if", "(", "isset", "(", "$", "array", "[", "'distance'", "]", ")", ")", "{", "$", "item", "->", "distance", "=", "(", "float", ")", "$", "array", "[", "'distance'", "]", ";", "}", "if", "(", "isset", "(", "$", "array", "[", "'highlights'", "]", ")", ")", "{", "$", "item", "->", "highlights", "=", "$", "array", "[", "'highlights'", "]", ";", "}", "if", "(", "isset", "(", "$", "array", "[", "'is_promoted'", "]", ")", "&&", "true", "===", "$", "array", "[", "'is_promoted'", "]", ")", "{", "$", "item", "->", "setPromoted", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "array", "[", "'score'", "]", ")", "&&", "!", "is_null", "(", "$", "array", "[", "'score'", "]", ")", ")", "{", "$", "item", "->", "setScore", "(", "(", "float", ")", "$", "array", "[", "'score'", "]", ")", ";", "}", "return", "$", "item", ";", "}" ]
Create from array. @param array $array @return Item
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Item.php#L529-L581
apisearch-io/php-client
Repository/RepositoryBucket.php
RepositoryBucket.addRepository
public function addRepository( string $appName, string $indexName, TransformableRepository $repository ) { $this->repositories[$appName][$indexName] = $repository; }
php
public function addRepository( string $appName, string $indexName, TransformableRepository $repository ) { $this->repositories[$appName][$indexName] = $repository; }
[ "public", "function", "addRepository", "(", "string", "$", "appName", ",", "string", "$", "indexName", ",", "TransformableRepository", "$", "repository", ")", "{", "$", "this", "->", "repositories", "[", "$", "appName", "]", "[", "$", "indexName", "]", "=", "$", "repository", ";", "}" ]
Add repository. @param string $appName @param string $indexName @param TransformableRepository $repository
[ "Add", "repository", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/RepositoryBucket.php#L37-L43
apisearch-io/php-client
Repository/RepositoryBucket.php
RepositoryBucket.findRepository
public function findRepository( string $appName, string $indexName ): ? TransformableRepository { if ( !isset($this->repositories[$appName]) || !isset($this->repositories[$appName][$indexName]) ) { return null; } return $this->repositories[$appName][$indexName]; }
php
public function findRepository( string $appName, string $indexName ): ? TransformableRepository { if ( !isset($this->repositories[$appName]) || !isset($this->repositories[$appName][$indexName]) ) { return null; } return $this->repositories[$appName][$indexName]; }
[ "public", "function", "findRepository", "(", "string", "$", "appName", ",", "string", "$", "indexName", ")", ":", "?", "TransformableRepository", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "repositories", "[", "$", "appName", "]", ")", "||", "!", "isset", "(", "$", "this", "->", "repositories", "[", "$", "appName", "]", "[", "$", "indexName", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "repositories", "[", "$", "appName", "]", "[", "$", "indexName", "]", ";", "}" ]
Get repository by name and index. @param string $appName @param string $indexName @return TransformableRepository|null
[ "Get", "repository", "by", "name", "and", "index", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/RepositoryBucket.php#L53-L65
apisearch-io/php-client
Query/ScoreStrategy.php
ScoreStrategy.createFieldBoosting
public static function createFieldBoosting( string $field, float $factor = self::DEFAULT_FACTOR, float $missing = self::DEFAULT_MISSING, string $modifier = self::MODIFIER_NONE, float $weight = self::DEFAULT_WEIGHT, Filter $filter = null, string $scoreMode = self::SCORE_MODE_AVG ): ScoreStrategy { $scoreStrategy = self::createDefault(); $scoreStrategy->type = self::BOOSTING_FIELD_VALUE; $scoreStrategy->configuration['field'] = $field; $scoreStrategy->configuration['factor'] = $factor; $scoreStrategy->configuration['missing'] = $missing; $scoreStrategy->configuration['modifier'] = $modifier; $scoreStrategy->weight = $weight; $scoreStrategy->filter = self::fixFilterFieldPath($filter); $scoreStrategy->scoreMode = $scoreMode; return $scoreStrategy; }
php
public static function createFieldBoosting( string $field, float $factor = self::DEFAULT_FACTOR, float $missing = self::DEFAULT_MISSING, string $modifier = self::MODIFIER_NONE, float $weight = self::DEFAULT_WEIGHT, Filter $filter = null, string $scoreMode = self::SCORE_MODE_AVG ): ScoreStrategy { $scoreStrategy = self::createDefault(); $scoreStrategy->type = self::BOOSTING_FIELD_VALUE; $scoreStrategy->configuration['field'] = $field; $scoreStrategy->configuration['factor'] = $factor; $scoreStrategy->configuration['missing'] = $missing; $scoreStrategy->configuration['modifier'] = $modifier; $scoreStrategy->weight = $weight; $scoreStrategy->filter = self::fixFilterFieldPath($filter); $scoreStrategy->scoreMode = $scoreMode; return $scoreStrategy; }
[ "public", "static", "function", "createFieldBoosting", "(", "string", "$", "field", ",", "float", "$", "factor", "=", "self", "::", "DEFAULT_FACTOR", ",", "float", "$", "missing", "=", "self", "::", "DEFAULT_MISSING", ",", "string", "$", "modifier", "=", "self", "::", "MODIFIER_NONE", ",", "float", "$", "weight", "=", "self", "::", "DEFAULT_WEIGHT", ",", "Filter", "$", "filter", "=", "null", ",", "string", "$", "scoreMode", "=", "self", "::", "SCORE_MODE_AVG", ")", ":", "ScoreStrategy", "{", "$", "scoreStrategy", "=", "self", "::", "createDefault", "(", ")", ";", "$", "scoreStrategy", "->", "type", "=", "self", "::", "BOOSTING_FIELD_VALUE", ";", "$", "scoreStrategy", "->", "configuration", "[", "'field'", "]", "=", "$", "field", ";", "$", "scoreStrategy", "->", "configuration", "[", "'factor'", "]", "=", "$", "factor", ";", "$", "scoreStrategy", "->", "configuration", "[", "'missing'", "]", "=", "$", "missing", ";", "$", "scoreStrategy", "->", "configuration", "[", "'modifier'", "]", "=", "$", "modifier", ";", "$", "scoreStrategy", "->", "weight", "=", "$", "weight", ";", "$", "scoreStrategy", "->", "filter", "=", "self", "::", "fixFilterFieldPath", "(", "$", "filter", ")", ";", "$", "scoreStrategy", "->", "scoreMode", "=", "$", "scoreMode", ";", "return", "$", "scoreStrategy", ";", "}" ]
Create default field scoring. @param string $field @param float $factor @param float $missing @param string $modifier @param float $weight @param Filter $filter @param string $scoreMode @return ScoreStrategy
[ "Create", "default", "field", "scoring", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategy.php#L275-L295
apisearch-io/php-client
Query/ScoreStrategy.php
ScoreStrategy.createCustomFunction
public static function createCustomFunction( string $function, float $weight = self::DEFAULT_WEIGHT, Filter $filter = null, string $scoreMode = self::SCORE_MODE_AVG ): ScoreStrategy { $scoreStrategy = self::createDefault(); $scoreStrategy->type = self::CUSTOM_FUNCTION; $scoreStrategy->configuration['function'] = $function; $scoreStrategy->weight = $weight; $scoreStrategy->filter = self::fixFilterFieldPath($filter); $scoreStrategy->scoreMode = $scoreMode; return $scoreStrategy; }
php
public static function createCustomFunction( string $function, float $weight = self::DEFAULT_WEIGHT, Filter $filter = null, string $scoreMode = self::SCORE_MODE_AVG ): ScoreStrategy { $scoreStrategy = self::createDefault(); $scoreStrategy->type = self::CUSTOM_FUNCTION; $scoreStrategy->configuration['function'] = $function; $scoreStrategy->weight = $weight; $scoreStrategy->filter = self::fixFilterFieldPath($filter); $scoreStrategy->scoreMode = $scoreMode; return $scoreStrategy; }
[ "public", "static", "function", "createCustomFunction", "(", "string", "$", "function", ",", "float", "$", "weight", "=", "self", "::", "DEFAULT_WEIGHT", ",", "Filter", "$", "filter", "=", "null", ",", "string", "$", "scoreMode", "=", "self", "::", "SCORE_MODE_AVG", ")", ":", "ScoreStrategy", "{", "$", "scoreStrategy", "=", "self", "::", "createDefault", "(", ")", ";", "$", "scoreStrategy", "->", "type", "=", "self", "::", "CUSTOM_FUNCTION", ";", "$", "scoreStrategy", "->", "configuration", "[", "'function'", "]", "=", "$", "function", ";", "$", "scoreStrategy", "->", "weight", "=", "$", "weight", ";", "$", "scoreStrategy", "->", "filter", "=", "self", "::", "fixFilterFieldPath", "(", "$", "filter", ")", ";", "$", "scoreStrategy", "->", "scoreMode", "=", "$", "scoreMode", ";", "return", "$", "scoreStrategy", ";", "}" ]
Create custom function scoring. @param string $function @param float $weight @param Filter $filter @param string $scoreMode @return ScoreStrategy
[ "Create", "custom", "function", "scoring", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategy.php#L307-L321
apisearch-io/php-client
Query/ScoreStrategy.php
ScoreStrategy.createDecayFunction
public static function createDecayFunction( string $type, string $field, string $origin, string $scale, string $offset, float $decay, float $weight = self::DEFAULT_WEIGHT, Filter $filter = null, string $scoreMode = self::SCORE_MODE_AVG ): ScoreStrategy { $scoreStrategy = self::createDefault(); $scoreStrategy->type = self::DECAY; $scoreStrategy->configuration['type'] = $type; $scoreStrategy->configuration['field'] = $field; $scoreStrategy->configuration['origin'] = $origin; $scoreStrategy->configuration['scale'] = $scale; $scoreStrategy->configuration['offset'] = $offset; $scoreStrategy->configuration['decay'] = $decay; $scoreStrategy->weight = $weight; $scoreStrategy->filter = self::fixFilterFieldPath($filter); $scoreStrategy->scoreMode = $scoreMode; return $scoreStrategy; }
php
public static function createDecayFunction( string $type, string $field, string $origin, string $scale, string $offset, float $decay, float $weight = self::DEFAULT_WEIGHT, Filter $filter = null, string $scoreMode = self::SCORE_MODE_AVG ): ScoreStrategy { $scoreStrategy = self::createDefault(); $scoreStrategy->type = self::DECAY; $scoreStrategy->configuration['type'] = $type; $scoreStrategy->configuration['field'] = $field; $scoreStrategy->configuration['origin'] = $origin; $scoreStrategy->configuration['scale'] = $scale; $scoreStrategy->configuration['offset'] = $offset; $scoreStrategy->configuration['decay'] = $decay; $scoreStrategy->weight = $weight; $scoreStrategy->filter = self::fixFilterFieldPath($filter); $scoreStrategy->scoreMode = $scoreMode; return $scoreStrategy; }
[ "public", "static", "function", "createDecayFunction", "(", "string", "$", "type", ",", "string", "$", "field", ",", "string", "$", "origin", ",", "string", "$", "scale", ",", "string", "$", "offset", ",", "float", "$", "decay", ",", "float", "$", "weight", "=", "self", "::", "DEFAULT_WEIGHT", ",", "Filter", "$", "filter", "=", "null", ",", "string", "$", "scoreMode", "=", "self", "::", "SCORE_MODE_AVG", ")", ":", "ScoreStrategy", "{", "$", "scoreStrategy", "=", "self", "::", "createDefault", "(", ")", ";", "$", "scoreStrategy", "->", "type", "=", "self", "::", "DECAY", ";", "$", "scoreStrategy", "->", "configuration", "[", "'type'", "]", "=", "$", "type", ";", "$", "scoreStrategy", "->", "configuration", "[", "'field'", "]", "=", "$", "field", ";", "$", "scoreStrategy", "->", "configuration", "[", "'origin'", "]", "=", "$", "origin", ";", "$", "scoreStrategy", "->", "configuration", "[", "'scale'", "]", "=", "$", "scale", ";", "$", "scoreStrategy", "->", "configuration", "[", "'offset'", "]", "=", "$", "offset", ";", "$", "scoreStrategy", "->", "configuration", "[", "'decay'", "]", "=", "$", "decay", ";", "$", "scoreStrategy", "->", "weight", "=", "$", "weight", ";", "$", "scoreStrategy", "->", "filter", "=", "self", "::", "fixFilterFieldPath", "(", "$", "filter", ")", ";", "$", "scoreStrategy", "->", "scoreMode", "=", "$", "scoreMode", ";", "return", "$", "scoreStrategy", ";", "}" ]
Create custom function scoring. @param string $type @param string $field @param string $origin @param string $scale @param string $offset @param float $decay @param float $weight @param Filter $filter @param string $scoreMode @return ScoreStrategy
[ "Create", "custom", "function", "scoring", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategy.php#L338-L362
apisearch-io/php-client
Query/ScoreStrategy.php
ScoreStrategy.fixFilterFieldPath
private static function fixFilterFieldPath(?Filter $filter): ? Filter { if (is_null($filter)) { return $filter; } $filterAsArray = $filter->toArray(); $filterAsArray['field'] = Item::getPathByField($filterAsArray['field']); return Filter::createFromArray($filterAsArray); }
php
private static function fixFilterFieldPath(?Filter $filter): ? Filter { if (is_null($filter)) { return $filter; } $filterAsArray = $filter->toArray(); $filterAsArray['field'] = Item::getPathByField($filterAsArray['field']); return Filter::createFromArray($filterAsArray); }
[ "private", "static", "function", "fixFilterFieldPath", "(", "?", "Filter", "$", "filter", ")", ":", "?", "Filter", "{", "if", "(", "is_null", "(", "$", "filter", ")", ")", "{", "return", "$", "filter", ";", "}", "$", "filterAsArray", "=", "$", "filter", "->", "toArray", "(", ")", ";", "$", "filterAsArray", "[", "'field'", "]", "=", "Item", "::", "getPathByField", "(", "$", "filterAsArray", "[", "'field'", "]", ")", ";", "return", "Filter", "::", "createFromArray", "(", "$", "filterAsArray", ")", ";", "}" ]
Fix filter path. @param Filter|null $filter @return Filter
[ "Fix", "filter", "path", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategy.php#L371-L381
apisearch-io/php-client
Query/ScoreStrategy.php
ScoreStrategy.toArray
public function toArray(): array { return [ 'type' => $this->type, 'configuration' => $this->configuration, 'weight' => $this->weight, 'score_mode' => $this->scoreMode, 'filter' => ($this->filter instanceof Filter ? $this ->filter ->toArray() : null), ]; }
php
public function toArray(): array { return [ 'type' => $this->type, 'configuration' => $this->configuration, 'weight' => $this->weight, 'score_mode' => $this->scoreMode, 'filter' => ($this->filter instanceof Filter ? $this ->filter ->toArray() : null), ]; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "[", "'type'", "=>", "$", "this", "->", "type", ",", "'configuration'", "=>", "$", "this", "->", "configuration", ",", "'weight'", "=>", "$", "this", "->", "weight", ",", "'score_mode'", "=>", "$", "this", "->", "scoreMode", ",", "'filter'", "=>", "(", "$", "this", "->", "filter", "instanceof", "Filter", "?", "$", "this", "->", "filter", "->", "toArray", "(", ")", ":", "null", ")", ",", "]", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategy.php#L388-L401
apisearch-io/php-client
Query/ScoreStrategy.php
ScoreStrategy.createFromArray
public static function createFromArray(array $array) { $scoreStrategy = new self(); $scoreStrategy->type = $array['type'] ?: self::DEFAULT_TYPE; $scoreStrategy->configuration = $array['configuration'] ?? []; $scoreStrategy->weight = $array['weight'] ?? self::DEFAULT_WEIGHT; $scoreStrategy->scoreMode = $array['score_mode'] ?? self::SCORE_MODE_AVG; $scoreStrategy->filter = is_array($array['filter']) ? Filter::createFromArray($array['filter']) : null; return $scoreStrategy; }
php
public static function createFromArray(array $array) { $scoreStrategy = new self(); $scoreStrategy->type = $array['type'] ?: self::DEFAULT_TYPE; $scoreStrategy->configuration = $array['configuration'] ?? []; $scoreStrategy->weight = $array['weight'] ?? self::DEFAULT_WEIGHT; $scoreStrategy->scoreMode = $array['score_mode'] ?? self::SCORE_MODE_AVG; $scoreStrategy->filter = is_array($array['filter']) ? Filter::createFromArray($array['filter']) : null; return $scoreStrategy; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", "{", "$", "scoreStrategy", "=", "new", "self", "(", ")", ";", "$", "scoreStrategy", "->", "type", "=", "$", "array", "[", "'type'", "]", "?", ":", "self", "::", "DEFAULT_TYPE", ";", "$", "scoreStrategy", "->", "configuration", "=", "$", "array", "[", "'configuration'", "]", "??", "[", "]", ";", "$", "scoreStrategy", "->", "weight", "=", "$", "array", "[", "'weight'", "]", "??", "self", "::", "DEFAULT_WEIGHT", ";", "$", "scoreStrategy", "->", "scoreMode", "=", "$", "array", "[", "'score_mode'", "]", "??", "self", "::", "SCORE_MODE_AVG", ";", "$", "scoreStrategy", "->", "filter", "=", "is_array", "(", "$", "array", "[", "'filter'", "]", ")", "?", "Filter", "::", "createFromArray", "(", "$", "array", "[", "'filter'", "]", ")", ":", "null", ";", "return", "$", "scoreStrategy", ";", "}" ]
Create from array. @param array $array @return self
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategy.php#L410-L422
apisearch-io/php-client
Result/Counter.php
Counter.createByActiveElements
public static function createByActiveElements( string $name, int $n, array $activeElements ): ? self { $values = Metadata::fromMetadata($name); if (is_null($values)) { return null; } return new self( $values, in_array($values['id'], $activeElements), $n ); }
php
public static function createByActiveElements( string $name, int $n, array $activeElements ): ? self { $values = Metadata::fromMetadata($name); if (is_null($values)) { return null; } return new self( $values, in_array($values['id'], $activeElements), $n ); }
[ "public", "static", "function", "createByActiveElements", "(", "string", "$", "name", ",", "int", "$", "n", ",", "array", "$", "activeElements", ")", ":", "?", "self", "{", "$", "values", "=", "Metadata", "::", "fromMetadata", "(", "$", "name", ")", ";", "if", "(", "is_null", "(", "$", "values", ")", ")", "{", "return", "null", ";", "}", "return", "new", "self", "(", "$", "values", ",", "in_array", "(", "$", "values", "[", "'id'", "]", ",", "$", "activeElements", ")", ",", "$", "n", ")", ";", "}" ]
Create or return null if the used element is not valid. @param string $name @param int $n @param array $activeElements @return Counter|null
[ "Create", "or", "return", "null", "if", "the", "used", "element", "is", "not", "valid", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Counter.php#L143-L159
apisearch-io/php-client
Model/Token.php
Token.toArray
public function toArray(): array { return [ 'uuid' => $this->tokenUUID->toArray(), 'app_uuid' => $this->appUUID->toArray(), 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt, 'indices' => array_map(function (IndexUUID $indexUUID) { return $indexUUID->toArray(); }, $this->indices), 'endpoints' => $this->endpoints, 'plugins' => $this->plugins, 'ttl' => $this->ttl, 'metadata' => $this->metadata, ]; }
php
public function toArray(): array { return [ 'uuid' => $this->tokenUUID->toArray(), 'app_uuid' => $this->appUUID->toArray(), 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt, 'indices' => array_map(function (IndexUUID $indexUUID) { return $indexUUID->toArray(); }, $this->indices), 'endpoints' => $this->endpoints, 'plugins' => $this->plugins, 'ttl' => $this->ttl, 'metadata' => $this->metadata, ]; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "[", "'uuid'", "=>", "$", "this", "->", "tokenUUID", "->", "toArray", "(", ")", ",", "'app_uuid'", "=>", "$", "this", "->", "appUUID", "->", "toArray", "(", ")", ",", "'created_at'", "=>", "$", "this", "->", "createdAt", ",", "'updated_at'", "=>", "$", "this", "->", "updatedAt", ",", "'indices'", "=>", "array_map", "(", "function", "(", "IndexUUID", "$", "indexUUID", ")", "{", "return", "$", "indexUUID", "->", "toArray", "(", ")", ";", "}", ",", "$", "this", "->", "indices", ")", ",", "'endpoints'", "=>", "$", "this", "->", "endpoints", ",", "'plugins'", "=>", "$", "this", "->", "plugins", ",", "'ttl'", "=>", "$", "this", "->", "ttl", ",", "'metadata'", "=>", "$", "this", "->", "metadata", ",", "]", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Token.php#L314-L329
apisearch-io/php-client
Model/Token.php
Token.createFromArray
public static function createFromArray(array $array) { if ( !isset($array['uuid']) || !isset($array['app_uuid']) ) { throw InvalidFormatException::tokenFormatNotValid(json_encode($array)); } $token = new self( TokenUUID::createFromArray($array['uuid']), AppUUID::createFromArray($array['app_uuid']), array_map(function (array $indexUUIDAsArray) { return IndexUUID::createFromArray($indexUUIDAsArray); }, ($array['indices'] ?? [])), $array['endpoints'] ?? [], $array['plugins'] ?? [], $array['ttl'] ?? self::DEFAULT_TTL, $array['metadata'] ?? [] ); $token->createdAt = $array['created_at']; $token->updatedAt = $array['updated_at']; return $token; }
php
public static function createFromArray(array $array) { if ( !isset($array['uuid']) || !isset($array['app_uuid']) ) { throw InvalidFormatException::tokenFormatNotValid(json_encode($array)); } $token = new self( TokenUUID::createFromArray($array['uuid']), AppUUID::createFromArray($array['app_uuid']), array_map(function (array $indexUUIDAsArray) { return IndexUUID::createFromArray($indexUUIDAsArray); }, ($array['indices'] ?? [])), $array['endpoints'] ?? [], $array['plugins'] ?? [], $array['ttl'] ?? self::DEFAULT_TTL, $array['metadata'] ?? [] ); $token->createdAt = $array['created_at']; $token->updatedAt = $array['updated_at']; return $token; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", "{", "if", "(", "!", "isset", "(", "$", "array", "[", "'uuid'", "]", ")", "||", "!", "isset", "(", "$", "array", "[", "'app_uuid'", "]", ")", ")", "{", "throw", "InvalidFormatException", "::", "tokenFormatNotValid", "(", "json_encode", "(", "$", "array", ")", ")", ";", "}", "$", "token", "=", "new", "self", "(", "TokenUUID", "::", "createFromArray", "(", "$", "array", "[", "'uuid'", "]", ")", ",", "AppUUID", "::", "createFromArray", "(", "$", "array", "[", "'app_uuid'", "]", ")", ",", "array_map", "(", "function", "(", "array", "$", "indexUUIDAsArray", ")", "{", "return", "IndexUUID", "::", "createFromArray", "(", "$", "indexUUIDAsArray", ")", ";", "}", ",", "(", "$", "array", "[", "'indices'", "]", "??", "[", "]", ")", ")", ",", "$", "array", "[", "'endpoints'", "]", "??", "[", "]", ",", "$", "array", "[", "'plugins'", "]", "??", "[", "]", ",", "$", "array", "[", "'ttl'", "]", "??", "self", "::", "DEFAULT_TTL", ",", "$", "array", "[", "'metadata'", "]", "??", "[", "]", ")", ";", "$", "token", "->", "createdAt", "=", "$", "array", "[", "'created_at'", "]", ";", "$", "token", "->", "updatedAt", "=", "$", "array", "[", "'updated_at'", "]", ";", "return", "$", "token", ";", "}" ]
Create from array. @param array $array @return self @throws InvalidFormatException
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Token.php#L340-L365
apisearch-io/php-client
Exporter/CSVExporter.php
CSVExporter.itemsToFormat
public function itemsToFormat(array $items): string { return $this->strToCSV(array_map(function (Item $item) { return [ $item->getId(), $item->getType(), json_encode($item->getMetadata()), json_encode($item->getIndexedMetadata()), json_encode($item->getSearchableMetadata()), json_encode($item->getExactMatchingMetadata()), json_encode($item->getSuggest()), json_encode( ($item->getCoordinate() instanceof Coordinate) ? $item->getCoordinate()->toArray() : null ), ]; }, $items)); }
php
public function itemsToFormat(array $items): string { return $this->strToCSV(array_map(function (Item $item) { return [ $item->getId(), $item->getType(), json_encode($item->getMetadata()), json_encode($item->getIndexedMetadata()), json_encode($item->getSearchableMetadata()), json_encode($item->getExactMatchingMetadata()), json_encode($item->getSuggest()), json_encode( ($item->getCoordinate() instanceof Coordinate) ? $item->getCoordinate()->toArray() : null ), ]; }, $items)); }
[ "public", "function", "itemsToFormat", "(", "array", "$", "items", ")", ":", "string", "{", "return", "$", "this", "->", "strToCSV", "(", "array_map", "(", "function", "(", "Item", "$", "item", ")", "{", "return", "[", "$", "item", "->", "getId", "(", ")", ",", "$", "item", "->", "getType", "(", ")", ",", "json_encode", "(", "$", "item", "->", "getMetadata", "(", ")", ")", ",", "json_encode", "(", "$", "item", "->", "getIndexedMetadata", "(", ")", ")", ",", "json_encode", "(", "$", "item", "->", "getSearchableMetadata", "(", ")", ")", ",", "json_encode", "(", "$", "item", "->", "getExactMatchingMetadata", "(", ")", ")", ",", "json_encode", "(", "$", "item", "->", "getSuggest", "(", ")", ")", ",", "json_encode", "(", "(", "$", "item", "->", "getCoordinate", "(", ")", "instanceof", "Coordinate", ")", "?", "$", "item", "->", "getCoordinate", "(", ")", "->", "toArray", "(", ")", ":", "null", ")", ",", "]", ";", "}", ",", "$", "items", ")", ")", ";", "}" ]
Convert array of Items to string format. @param Item[] $items @return string
[ "Convert", "array", "of", "Items", "to", "string", "format", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/CSVExporter.php#L53-L71
apisearch-io/php-client
Exporter/CSVExporter.php
CSVExporter.formatToItems
public function formatToItems(string $data): array { return array_map(function (string $line) { $item = str_getcsv($line, ','); $itemAsArray = [ 'uuid' => [ 'id' => $item[0], 'type' => $item[1], ], 'metadata' => json_decode($item[2], true), 'indexed_metadata' => json_decode($item[3], true), 'searchable_metadata' => json_decode($item[4], true), 'exact_matching_metadata' => json_decode($item[5], true), 'suggest' => json_decode($item[6], true), ]; if (!empty($item[7])) { $itemAsArray['coordinate'] = json_decode($item[7], true); } return Item::createFromArray($itemAsArray); }, str_getcsv($data, "\n")); }
php
public function formatToItems(string $data): array { return array_map(function (string $line) { $item = str_getcsv($line, ','); $itemAsArray = [ 'uuid' => [ 'id' => $item[0], 'type' => $item[1], ], 'metadata' => json_decode($item[2], true), 'indexed_metadata' => json_decode($item[3], true), 'searchable_metadata' => json_decode($item[4], true), 'exact_matching_metadata' => json_decode($item[5], true), 'suggest' => json_decode($item[6], true), ]; if (!empty($item[7])) { $itemAsArray['coordinate'] = json_decode($item[7], true); } return Item::createFromArray($itemAsArray); }, str_getcsv($data, "\n")); }
[ "public", "function", "formatToItems", "(", "string", "$", "data", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "string", "$", "line", ")", "{", "$", "item", "=", "str_getcsv", "(", "$", "line", ",", "','", ")", ";", "$", "itemAsArray", "=", "[", "'uuid'", "=>", "[", "'id'", "=>", "$", "item", "[", "0", "]", ",", "'type'", "=>", "$", "item", "[", "1", "]", ",", "]", ",", "'metadata'", "=>", "json_decode", "(", "$", "item", "[", "2", "]", ",", "true", ")", ",", "'indexed_metadata'", "=>", "json_decode", "(", "$", "item", "[", "3", "]", ",", "true", ")", ",", "'searchable_metadata'", "=>", "json_decode", "(", "$", "item", "[", "4", "]", ",", "true", ")", ",", "'exact_matching_metadata'", "=>", "json_decode", "(", "$", "item", "[", "5", "]", ",", "true", ")", ",", "'suggest'", "=>", "json_decode", "(", "$", "item", "[", "6", "]", ",", "true", ")", ",", "]", ";", "if", "(", "!", "empty", "(", "$", "item", "[", "7", "]", ")", ")", "{", "$", "itemAsArray", "[", "'coordinate'", "]", "=", "json_decode", "(", "$", "item", "[", "7", "]", ",", "true", ")", ";", "}", "return", "Item", "::", "createFromArray", "(", "$", "itemAsArray", ")", ";", "}", ",", "str_getcsv", "(", "$", "data", ",", "\"\\n\"", ")", ")", ";", "}" ]
Convert string formatted to array of Items. @param string $data @return Item[]
[ "Convert", "string", "formatted", "to", "array", "of", "Items", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/CSVExporter.php#L80-L102
apisearch-io/php-client
Exporter/CSVExporter.php
CSVExporter.strToCSV
private function strToCSV( array $items, string $delimiter = ',', string $enclosure = '"' ) { $fp = fopen('php://temp', 'r+b'); foreach ($items as $item) { fputcsv($fp, $item, $delimiter, $enclosure); } rewind($fp); $data = rtrim(stream_get_contents($fp), "\n"); fclose($fp); return $data; }
php
private function strToCSV( array $items, string $delimiter = ',', string $enclosure = '"' ) { $fp = fopen('php://temp', 'r+b'); foreach ($items as $item) { fputcsv($fp, $item, $delimiter, $enclosure); } rewind($fp); $data = rtrim(stream_get_contents($fp), "\n"); fclose($fp); return $data; }
[ "private", "function", "strToCSV", "(", "array", "$", "items", ",", "string", "$", "delimiter", "=", "','", ",", "string", "$", "enclosure", "=", "'\"'", ")", "{", "$", "fp", "=", "fopen", "(", "'php://temp'", ",", "'r+b'", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "fputcsv", "(", "$", "fp", ",", "$", "item", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "rewind", "(", "$", "fp", ")", ";", "$", "data", "=", "rtrim", "(", "stream_get_contents", "(", "$", "fp", ")", ",", "\"\\n\"", ")", ";", "fclose", "(", "$", "fp", ")", ";", "return", "$", "data", ";", "}" ]
@param array $items @param string $delimiter @param string $enclosure @return string
[ "@param", "array", "$items", "@param", "string", "$delimiter", "@param", "string", "$enclosure" ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/CSVExporter.php#L111-L125
apisearch-io/php-client
Repository/RepositoryReference.php
RepositoryReference.create
public static function create( AppUUID $appUUID = null, IndexUUID $indexUUID = null ): RepositoryReference { return new self($appUUID, $indexUUID); }
php
public static function create( AppUUID $appUUID = null, IndexUUID $indexUUID = null ): RepositoryReference { return new self($appUUID, $indexUUID); }
[ "public", "static", "function", "create", "(", "AppUUID", "$", "appUUID", "=", "null", ",", "IndexUUID", "$", "indexUUID", "=", "null", ")", ":", "RepositoryReference", "{", "return", "new", "self", "(", "$", "appUUID", ",", "$", "indexUUID", ")", ";", "}" ]
Create by appUUID and indexUUID. @param AppUUID $appUUID @param IndexUUID $indexUUID @return RepositoryReference
[ "Create", "by", "appUUID", "and", "indexUUID", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/RepositoryReference.php#L82-L87
apisearch-io/php-client
Repository/RepositoryReference.php
RepositoryReference.compose
public function compose(): string { return sprintf('%s_%s', $this->appUUID instanceof AppUUID ? str_replace('_', '-', $this->appUUID->composeUUID()) : '', $this->indexUUID instanceof IndexUUID ? str_replace('_', '-', $this->indexUUID->composeUUID()) : '' ); }
php
public function compose(): string { return sprintf('%s_%s', $this->appUUID instanceof AppUUID ? str_replace('_', '-', $this->appUUID->composeUUID()) : '', $this->indexUUID instanceof IndexUUID ? str_replace('_', '-', $this->indexUUID->composeUUID()) : '' ); }
[ "public", "function", "compose", "(", ")", ":", "string", "{", "return", "sprintf", "(", "'%s_%s'", ",", "$", "this", "->", "appUUID", "instanceof", "AppUUID", "?", "str_replace", "(", "'_'", ",", "'-'", ",", "$", "this", "->", "appUUID", "->", "composeUUID", "(", ")", ")", ":", "''", ",", "$", "this", "->", "indexUUID", "instanceof", "IndexUUID", "?", "str_replace", "(", "'_'", ",", "'-'", ",", "$", "this", "->", "indexUUID", "->", "composeUUID", "(", ")", ")", ":", "''", ")", ";", "}" ]
Compose. @return string
[ "Compose", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/RepositoryReference.php#L109-L119
apisearch-io/php-client
Repository/RepositoryReference.php
RepositoryReference.createFromComposed
public static function createFromComposed(string $composed): RepositoryReference { list($appUUIDComposed, $indexUUIDComposed) = explode('_', $composed, 2); return RepositoryReference::create( AppUUID::createById($appUUIDComposed), IndexUUID::createById($indexUUIDComposed) ); }
php
public static function createFromComposed(string $composed): RepositoryReference { list($appUUIDComposed, $indexUUIDComposed) = explode('_', $composed, 2); return RepositoryReference::create( AppUUID::createById($appUUIDComposed), IndexUUID::createById($indexUUIDComposed) ); }
[ "public", "static", "function", "createFromComposed", "(", "string", "$", "composed", ")", ":", "RepositoryReference", "{", "list", "(", "$", "appUUIDComposed", ",", "$", "indexUUIDComposed", ")", "=", "explode", "(", "'_'", ",", "$", "composed", ",", "2", ")", ";", "return", "RepositoryReference", "::", "create", "(", "AppUUID", "::", "createById", "(", "$", "appUUIDComposed", ")", ",", "IndexUUID", "::", "createById", "(", "$", "indexUUIDComposed", ")", ")", ";", "}" ]
Create from composed. @param string $composed @return RepositoryReference
[ "Create", "from", "composed", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/RepositoryReference.php#L128-L136
apisearch-io/php-client
Exporter/YamlExporter.php
YamlExporter.itemsToFormat
public function itemsToFormat(array $items): string { $this->checkDependencies(); $headers = [ 'metadata' => [], 'indexed_metadata' => [], 'searchable_metadata' => [], ]; $data = [ 'header' => &$headers, ]; $iteration = 0; foreach ($items as $item) { $this->enrichHeadersWithItem( $headers, $item ); ++$iteration; $data["item_$iteration"] = array_filter( ( $item->getUUID()->toArray() + $item->getMetadata() + $item->getIndexedMetadata() + $item->getSearchableMetadata() + [ 'exact_matching' => $item->getExactMatchingMetadata(), 'suggest' => $item->getSuggest(), 'coordinate' => $item->getCoordinate() instanceof Coordinate ? $item->getCoordinate()->toArray() : null, ] ), function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); } ); } return Yaml::dump($data); }
php
public function itemsToFormat(array $items): string { $this->checkDependencies(); $headers = [ 'metadata' => [], 'indexed_metadata' => [], 'searchable_metadata' => [], ]; $data = [ 'header' => &$headers, ]; $iteration = 0; foreach ($items as $item) { $this->enrichHeadersWithItem( $headers, $item ); ++$iteration; $data["item_$iteration"] = array_filter( ( $item->getUUID()->toArray() + $item->getMetadata() + $item->getIndexedMetadata() + $item->getSearchableMetadata() + [ 'exact_matching' => $item->getExactMatchingMetadata(), 'suggest' => $item->getSuggest(), 'coordinate' => $item->getCoordinate() instanceof Coordinate ? $item->getCoordinate()->toArray() : null, ] ), function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); } ); } return Yaml::dump($data); }
[ "public", "function", "itemsToFormat", "(", "array", "$", "items", ")", ":", "string", "{", "$", "this", "->", "checkDependencies", "(", ")", ";", "$", "headers", "=", "[", "'metadata'", "=>", "[", "]", ",", "'indexed_metadata'", "=>", "[", "]", ",", "'searchable_metadata'", "=>", "[", "]", ",", "]", ";", "$", "data", "=", "[", "'header'", "=>", "&", "$", "headers", ",", "]", ";", "$", "iteration", "=", "0", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "this", "->", "enrichHeadersWithItem", "(", "$", "headers", ",", "$", "item", ")", ";", "++", "$", "iteration", ";", "$", "data", "[", "\"item_$iteration\"", "]", "=", "array_filter", "(", "(", "$", "item", "->", "getUUID", "(", ")", "->", "toArray", "(", ")", "+", "$", "item", "->", "getMetadata", "(", ")", "+", "$", "item", "->", "getIndexedMetadata", "(", ")", "+", "$", "item", "->", "getSearchableMetadata", "(", ")", "+", "[", "'exact_matching'", "=>", "$", "item", "->", "getExactMatchingMetadata", "(", ")", ",", "'suggest'", "=>", "$", "item", "->", "getSuggest", "(", ")", ",", "'coordinate'", "=>", "$", "item", "->", "getCoordinate", "(", ")", "instanceof", "Coordinate", "?", "$", "item", "->", "getCoordinate", "(", ")", "->", "toArray", "(", ")", ":", "null", ",", "]", ")", ",", "function", "(", "$", "element", ")", "{", "return", "!", "(", "is_null", "(", "$", "element", ")", "||", "(", "is_array", "(", "$", "element", ")", "&&", "empty", "(", "$", "element", ")", ")", ")", ";", "}", ")", ";", "}", "return", "Yaml", "::", "dump", "(", "$", "data", ")", ";", "}" ]
Convert array of Items to string format. This yaml format transforms each item into a plain and logic-less set of data in order to be more comprehensive for the human eyes. To make this happens, this format must work with some headers to define the composition of the item hydration fields: metadata: - field1 - field2 indexed_metadata: - field3 - field4 item_1: ... item_2 ... @param Item[] $items @return string
[ "Convert", "array", "of", "Items", "to", "string", "format", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/YamlExporter.php#L74-L119
apisearch-io/php-client
Exporter/YamlExporter.php
YamlExporter.formatToItems
public function formatToItems(string $data): array { $this->checkDependencies(); $data = Yaml::parse($data); $header = $data['header']; unset($data['header']); $items = []; foreach ($data as $itemAsArray) { $items[] = Item::createFromArray( [ 'uuid' => [ 'id' => $itemAsArray['id'], 'type' => $itemAsArray['type'] ?? 'item', ], 'suggest' => ($itemAsArray['suggest'] ?? []), 'exact_matching_metadata' => ($itemAsArray['exact_matching'] ?? []), 'coordinate' => ($itemAsArray['coordinate'] ?? null), ] + $this->parseFieldsFromHeaderAndItemAsArray( $header, $itemAsArray ) ); } return $items; }
php
public function formatToItems(string $data): array { $this->checkDependencies(); $data = Yaml::parse($data); $header = $data['header']; unset($data['header']); $items = []; foreach ($data as $itemAsArray) { $items[] = Item::createFromArray( [ 'uuid' => [ 'id' => $itemAsArray['id'], 'type' => $itemAsArray['type'] ?? 'item', ], 'suggest' => ($itemAsArray['suggest'] ?? []), 'exact_matching_metadata' => ($itemAsArray['exact_matching'] ?? []), 'coordinate' => ($itemAsArray['coordinate'] ?? null), ] + $this->parseFieldsFromHeaderAndItemAsArray( $header, $itemAsArray ) ); } return $items; }
[ "public", "function", "formatToItems", "(", "string", "$", "data", ")", ":", "array", "{", "$", "this", "->", "checkDependencies", "(", ")", ";", "$", "data", "=", "Yaml", "::", "parse", "(", "$", "data", ")", ";", "$", "header", "=", "$", "data", "[", "'header'", "]", ";", "unset", "(", "$", "data", "[", "'header'", "]", ")", ";", "$", "items", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "itemAsArray", ")", "{", "$", "items", "[", "]", "=", "Item", "::", "createFromArray", "(", "[", "'uuid'", "=>", "[", "'id'", "=>", "$", "itemAsArray", "[", "'id'", "]", ",", "'type'", "=>", "$", "itemAsArray", "[", "'type'", "]", "??", "'item'", ",", "]", ",", "'suggest'", "=>", "(", "$", "itemAsArray", "[", "'suggest'", "]", "??", "[", "]", ")", ",", "'exact_matching_metadata'", "=>", "(", "$", "itemAsArray", "[", "'exact_matching'", "]", "??", "[", "]", ")", ",", "'coordinate'", "=>", "(", "$", "itemAsArray", "[", "'coordinate'", "]", "??", "null", ")", ",", "]", "+", "$", "this", "->", "parseFieldsFromHeaderAndItemAsArray", "(", "$", "header", ",", "$", "itemAsArray", ")", ")", ";", "}", "return", "$", "items", ";", "}" ]
Convert string formatted to array of Items. @param string $data @return Item[]
[ "Convert", "string", "formatted", "to", "array", "of", "Items", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/YamlExporter.php#L128-L155
apisearch-io/php-client
Exporter/YamlExporter.php
YamlExporter.enrichHeadersWithItem
private function enrichHeadersWithItem( array &$headers, Item $item ) { $this->enrichHeaderWithFields($headers, 'metadata', $item->getMetadata()); $this->enrichHeaderWithFields($headers, 'indexed_metadata', $item->getIndexedMetadata()); $this->enrichHeaderWithFields($headers, 'searchable_metadata', $item->getSearchableMetadata()); }
php
private function enrichHeadersWithItem( array &$headers, Item $item ) { $this->enrichHeaderWithFields($headers, 'metadata', $item->getMetadata()); $this->enrichHeaderWithFields($headers, 'indexed_metadata', $item->getIndexedMetadata()); $this->enrichHeaderWithFields($headers, 'searchable_metadata', $item->getSearchableMetadata()); }
[ "private", "function", "enrichHeadersWithItem", "(", "array", "&", "$", "headers", ",", "Item", "$", "item", ")", "{", "$", "this", "->", "enrichHeaderWithFields", "(", "$", "headers", ",", "'metadata'", ",", "$", "item", "->", "getMetadata", "(", ")", ")", ";", "$", "this", "->", "enrichHeaderWithFields", "(", "$", "headers", ",", "'indexed_metadata'", ",", "$", "item", "->", "getIndexedMetadata", "(", ")", ")", ";", "$", "this", "->", "enrichHeaderWithFields", "(", "$", "headers", ",", "'searchable_metadata'", ",", "$", "item", "->", "getSearchableMetadata", "(", ")", ")", ";", "}" ]
Enrich headers list with an item. @param array $headers @param Item $item
[ "Enrich", "headers", "list", "with", "an", "item", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/YamlExporter.php#L163-L170
apisearch-io/php-client
Exporter/YamlExporter.php
YamlExporter.enrichHeaderWithFields
private function enrichHeaderWithFields( array &$headers, string $section, array $fields ) { foreach ($fields as $fieldName => $_) { if (!in_array($fieldName, $headers[$section])) { $headers[$section][] = $fieldName; } } }
php
private function enrichHeaderWithFields( array &$headers, string $section, array $fields ) { foreach ($fields as $fieldName => $_) { if (!in_array($fieldName, $headers[$section])) { $headers[$section][] = $fieldName; } } }
[ "private", "function", "enrichHeaderWithFields", "(", "array", "&", "$", "headers", ",", "string", "$", "section", ",", "array", "$", "fields", ")", "{", "foreach", "(", "$", "fields", "as", "$", "fieldName", "=>", "$", "_", ")", "{", "if", "(", "!", "in_array", "(", "$", "fieldName", ",", "$", "headers", "[", "$", "section", "]", ")", ")", "{", "$", "headers", "[", "$", "section", "]", "[", "]", "=", "$", "fieldName", ";", "}", "}", "}" ]
Enrich headers list with an item. @param array $headers @param string $section @param array $fields
[ "Enrich", "headers", "list", "with", "an", "item", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/YamlExporter.php#L179-L189
apisearch-io/php-client
Exporter/YamlExporter.php
YamlExporter.parseFieldsFromHeaderAndItemAsArray
private function parseFieldsFromHeaderAndItemAsArray( array $header, array $item ) { return [ 'metadata' => $this->parseSectionFromHeaderAndItemAsArray($header, 'metadata', $item), 'indexed_metadata' => $this->parseSectionFromHeaderAndItemAsArray($header, 'indexed_metadata', $item), 'searchable_metadata' => $this->parseSectionFromHeaderAndItemAsArray($header, 'searchable_metadata', $item), ]; }
php
private function parseFieldsFromHeaderAndItemAsArray( array $header, array $item ) { return [ 'metadata' => $this->parseSectionFromHeaderAndItemAsArray($header, 'metadata', $item), 'indexed_metadata' => $this->parseSectionFromHeaderAndItemAsArray($header, 'indexed_metadata', $item), 'searchable_metadata' => $this->parseSectionFromHeaderAndItemAsArray($header, 'searchable_metadata', $item), ]; }
[ "private", "function", "parseFieldsFromHeaderAndItemAsArray", "(", "array", "$", "header", ",", "array", "$", "item", ")", "{", "return", "[", "'metadata'", "=>", "$", "this", "->", "parseSectionFromHeaderAndItemAsArray", "(", "$", "header", ",", "'metadata'", ",", "$", "item", ")", ",", "'indexed_metadata'", "=>", "$", "this", "->", "parseSectionFromHeaderAndItemAsArray", "(", "$", "header", ",", "'indexed_metadata'", ",", "$", "item", ")", ",", "'searchable_metadata'", "=>", "$", "this", "->", "parseSectionFromHeaderAndItemAsArray", "(", "$", "header", ",", "'searchable_metadata'", ",", "$", "item", ")", ",", "]", ";", "}" ]
Parse fields from item having header. @param array $header @param array $item @return array
[ "Parse", "fields", "from", "item", "having", "header", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/YamlExporter.php#L199-L208
apisearch-io/php-client
Exporter/YamlExporter.php
YamlExporter.parseSectionFromHeaderAndItemAsArray
private function parseSectionFromHeaderAndItemAsArray( array $header, string $section, array $item ) { return array_intersect_key( $item, array_flip($header[$section] ?? []) ); }
php
private function parseSectionFromHeaderAndItemAsArray( array $header, string $section, array $item ) { return array_intersect_key( $item, array_flip($header[$section] ?? []) ); }
[ "private", "function", "parseSectionFromHeaderAndItemAsArray", "(", "array", "$", "header", ",", "string", "$", "section", ",", "array", "$", "item", ")", "{", "return", "array_intersect_key", "(", "$", "item", ",", "array_flip", "(", "$", "header", "[", "$", "section", "]", "??", "[", "]", ")", ")", ";", "}" ]
Parse section fields from item having header. @param array $header @param string $section @param array $item @return array
[ "Parse", "section", "fields", "from", "item", "having", "header", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/YamlExporter.php#L219-L228
apisearch-io/php-client
Result/Result.php
Result.create
public static function create( ?string $queryUUID, int $totalItems, int $totalHits, ? Aggregations $aggregations, array $suggests, array $items ): self { $result = new self( $queryUUID, $totalItems, $totalHits ); $result->aggregations = $aggregations; $result->suggests = $suggests; $result->items = $items; return $result; }
php
public static function create( ?string $queryUUID, int $totalItems, int $totalHits, ? Aggregations $aggregations, array $suggests, array $items ): self { $result = new self( $queryUUID, $totalItems, $totalHits ); $result->aggregations = $aggregations; $result->suggests = $suggests; $result->items = $items; return $result; }
[ "public", "static", "function", "create", "(", "?", "string", "$", "queryUUID", ",", "int", "$", "totalItems", ",", "int", "$", "totalHits", ",", "?", "Aggregations", "$", "aggregations", ",", "array", "$", "suggests", ",", "array", "$", "items", ")", ":", "self", "{", "$", "result", "=", "new", "self", "(", "$", "queryUUID", ",", "$", "totalItems", ",", "$", "totalHits", ")", ";", "$", "result", "->", "aggregations", "=", "$", "aggregations", ";", "$", "result", "->", "suggests", "=", "$", "suggests", ";", "$", "result", "->", "items", "=", "$", "items", ";", "return", "$", "result", ";", "}" ]
Create by. @param string|null $queryUUID @param int $totalItems @param int $totalHits @param Aggregations|null $aggregations @param string[] $suggests @param Item[] $items @return Result
[ "Create", "by", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Result.php#L111-L130
apisearch-io/php-client
Result/Result.php
Result.getItemsGroupedByTypes
public function getItemsGroupedByTypes(): array { if (is_array($this->itemsGroupedByTypeCache)) { return $this->itemsGroupedByTypeCache; } $items = $this->getItems(); $itemsGroupedByType = []; foreach ($items as $item) { if (!isset($itemsGroupedByType[$item->getType()])) { $itemsGroupedByType[$item->getType()] = []; } $itemsGroupedByType[$item->getType()][] = $item; } $this->itemsGroupedByTypeCache = $itemsGroupedByType; return $itemsGroupedByType; }
php
public function getItemsGroupedByTypes(): array { if (is_array($this->itemsGroupedByTypeCache)) { return $this->itemsGroupedByTypeCache; } $items = $this->getItems(); $itemsGroupedByType = []; foreach ($items as $item) { if (!isset($itemsGroupedByType[$item->getType()])) { $itemsGroupedByType[$item->getType()] = []; } $itemsGroupedByType[$item->getType()][] = $item; } $this->itemsGroupedByTypeCache = $itemsGroupedByType; return $itemsGroupedByType; }
[ "public", "function", "getItemsGroupedByTypes", "(", ")", ":", "array", "{", "if", "(", "is_array", "(", "$", "this", "->", "itemsGroupedByTypeCache", ")", ")", "{", "return", "$", "this", "->", "itemsGroupedByTypeCache", ";", "}", "$", "items", "=", "$", "this", "->", "getItems", "(", ")", ";", "$", "itemsGroupedByType", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "!", "isset", "(", "$", "itemsGroupedByType", "[", "$", "item", "->", "getType", "(", ")", "]", ")", ")", "{", "$", "itemsGroupedByType", "[", "$", "item", "->", "getType", "(", ")", "]", "=", "[", "]", ";", "}", "$", "itemsGroupedByType", "[", "$", "item", "->", "getType", "(", ")", "]", "[", "]", "=", "$", "item", ";", "}", "$", "this", "->", "itemsGroupedByTypeCache", "=", "$", "itemsGroupedByType", ";", "return", "$", "itemsGroupedByType", ";", "}" ]
Get items grouped by type. @return array
[ "Get", "items", "grouped", "by", "type", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Result.php#L172-L190
apisearch-io/php-client
Result/Result.php
Result.getItemsByTypes
public function getItemsByTypes(array $types): array { return array_filter( $this->getItems(), function (Item $item) use ($types) { return in_array( $item->getType(), $types ); } ); }
php
public function getItemsByTypes(array $types): array { return array_filter( $this->getItems(), function (Item $item) use ($types) { return in_array( $item->getType(), $types ); } ); }
[ "public", "function", "getItemsByTypes", "(", "array", "$", "types", ")", ":", "array", "{", "return", "array_filter", "(", "$", "this", "->", "getItems", "(", ")", ",", "function", "(", "Item", "$", "item", ")", "use", "(", "$", "types", ")", "{", "return", "in_array", "(", "$", "item", "->", "getType", "(", ")", ",", "$", "types", ")", ";", "}", ")", ";", "}" ]
Get Items by a certain types. @param array $types @return Item[]
[ "Get", "Items", "by", "a", "certain", "types", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Result.php#L211-L222
apisearch-io/php-client
Result/Result.php
Result.getFirstItem
public function getFirstItem() { $results = $this->getItems(); if (empty($results)) { return null; } $firstItem = reset($results); return $firstItem; }
php
public function getFirstItem() { $results = $this->getItems(); if (empty($results)) { return null; } $firstItem = reset($results); return $firstItem; }
[ "public", "function", "getFirstItem", "(", ")", "{", "$", "results", "=", "$", "this", "->", "getItems", "(", ")", ";", "if", "(", "empty", "(", "$", "results", ")", ")", "{", "return", "null", ";", "}", "$", "firstItem", "=", "reset", "(", "$", "results", ")", ";", "return", "$", "firstItem", ";", "}" ]
Get first result. @return Item|null
[ "Get", "first", "result", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Result.php#L229-L240
apisearch-io/php-client
Result/Result.php
Result.getAggregation
public function getAggregation(string $name): ? Aggregation { if (is_null($this->aggregations)) { return null; } return $this ->aggregations ->getAggregation($name); }
php
public function getAggregation(string $name): ? Aggregation { if (is_null($this->aggregations)) { return null; } return $this ->aggregations ->getAggregation($name); }
[ "public", "function", "getAggregation", "(", "string", "$", "name", ")", ":", "?", "Aggregation", "{", "if", "(", "is_null", "(", "$", "this", "->", "aggregations", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "aggregations", "->", "getAggregation", "(", "$", "name", ")", ";", "}" ]
Get aggregation. @param string $name @return Aggregation|null
[ "Get", "aggregation", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Result.php#L269-L278
apisearch-io/php-client
Result/Result.php
Result.hasNotEmptyAggregation
public function hasNotEmptyAggregation(string $name): bool { if (is_null($this->aggregations)) { return false; } return $this ->aggregations ->hasNotEmptyAggregation($name); }
php
public function hasNotEmptyAggregation(string $name): bool { if (is_null($this->aggregations)) { return false; } return $this ->aggregations ->hasNotEmptyAggregation($name); }
[ "public", "function", "hasNotEmptyAggregation", "(", "string", "$", "name", ")", ":", "bool", "{", "if", "(", "is_null", "(", "$", "this", "->", "aggregations", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "aggregations", "->", "hasNotEmptyAggregation", "(", "$", "name", ")", ";", "}" ]
Has not empty aggregation. @param string $name @return bool
[ "Has", "not", "empty", "aggregation", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Result.php#L287-L296
apisearch-io/php-client
Result/Result.php
Result.toArray
public function toArray(): array { return array_filter([ 'query_uuid' => $this->queryUUID, 'total_items' => $this->totalItems, 'total_hits' => $this->totalHits, 'items' => array_map(function (Item $item) { return $item->toArray(); }, $this->items), 'aggregations' => $this->aggregations instanceof Aggregations ? $this->aggregations->toArray() : null, 'suggests' => $this->suggests, 'subresults' => array_map(function (Result $result) { return $result->toArray(); }, $this->subresults), ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
php
public function toArray(): array { return array_filter([ 'query_uuid' => $this->queryUUID, 'total_items' => $this->totalItems, 'total_hits' => $this->totalHits, 'items' => array_map(function (Item $item) { return $item->toArray(); }, $this->items), 'aggregations' => $this->aggregations instanceof Aggregations ? $this->aggregations->toArray() : null, 'suggests' => $this->suggests, 'subresults' => array_map(function (Result $result) { return $result->toArray(); }, $this->subresults), ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "array_filter", "(", "[", "'query_uuid'", "=>", "$", "this", "->", "queryUUID", ",", "'total_items'", "=>", "$", "this", "->", "totalItems", ",", "'total_hits'", "=>", "$", "this", "->", "totalHits", ",", "'items'", "=>", "array_map", "(", "function", "(", "Item", "$", "item", ")", "{", "return", "$", "item", "->", "toArray", "(", ")", ";", "}", ",", "$", "this", "->", "items", ")", ",", "'aggregations'", "=>", "$", "this", "->", "aggregations", "instanceof", "Aggregations", "?", "$", "this", "->", "aggregations", "->", "toArray", "(", ")", ":", "null", ",", "'suggests'", "=>", "$", "this", "->", "suggests", ",", "'subresults'", "=>", "array_map", "(", "function", "(", "Result", "$", "result", ")", "{", "return", "$", "result", "->", "toArray", "(", ")", ";", "}", ",", "$", "this", "->", "subresults", ")", ",", "]", ",", "function", "(", "$", "element", ")", "{", "return", "!", "(", "is_null", "(", "$", "element", ")", "||", "(", "is_array", "(", "$", "element", ")", "&&", "empty", "(", "$", "element", ")", ")", ")", ";", "}", ")", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Result.php#L363-L386
apisearch-io/php-client
Result/Result.php
Result.createFromArray
public static function createFromArray(array $array): self { $result = self::create( $array['query_uuid'] ?? '', $array['total_items'] ?? 0, $array['total_hits'] ?? 0, isset($array['aggregations']) ? Aggregations::createFromArray($array['aggregations']) : null, $array['suggests'] ?? [], array_map(function (array $item) { return Item::createFromArray($item); }, $array['items'] ?? []) ); $result->subresults = array_filter( array_map(function (array $subresultAsArray) { return Result::createFromArray($subresultAsArray); }, $array['subresults'] ?? []) ); return $result; }
php
public static function createFromArray(array $array): self { $result = self::create( $array['query_uuid'] ?? '', $array['total_items'] ?? 0, $array['total_hits'] ?? 0, isset($array['aggregations']) ? Aggregations::createFromArray($array['aggregations']) : null, $array['suggests'] ?? [], array_map(function (array $item) { return Item::createFromArray($item); }, $array['items'] ?? []) ); $result->subresults = array_filter( array_map(function (array $subresultAsArray) { return Result::createFromArray($subresultAsArray); }, $array['subresults'] ?? []) ); return $result; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", ":", "self", "{", "$", "result", "=", "self", "::", "create", "(", "$", "array", "[", "'query_uuid'", "]", "??", "''", ",", "$", "array", "[", "'total_items'", "]", "??", "0", ",", "$", "array", "[", "'total_hits'", "]", "??", "0", ",", "isset", "(", "$", "array", "[", "'aggregations'", "]", ")", "?", "Aggregations", "::", "createFromArray", "(", "$", "array", "[", "'aggregations'", "]", ")", ":", "null", ",", "$", "array", "[", "'suggests'", "]", "??", "[", "]", ",", "array_map", "(", "function", "(", "array", "$", "item", ")", "{", "return", "Item", "::", "createFromArray", "(", "$", "item", ")", ";", "}", ",", "$", "array", "[", "'items'", "]", "??", "[", "]", ")", ")", ";", "$", "result", "->", "subresults", "=", "array_filter", "(", "array_map", "(", "function", "(", "array", "$", "subresultAsArray", ")", "{", "return", "Result", "::", "createFromArray", "(", "$", "subresultAsArray", ")", ";", "}", ",", "$", "array", "[", "'subresults'", "]", "??", "[", "]", ")", ")", ";", "return", "$", "result", ";", "}" ]
Create from array. @param array $array @return Result
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Result.php#L395-L417
apisearch-io/php-client
User/UserRepositoryBucket.php
UserRepositoryBucket.findRepository
public function findRepository(string $name): ? UserRepository { return isset($this->repositories[$name]) ? $this->repositories[$name] : null; }
php
public function findRepository(string $name): ? UserRepository { return isset($this->repositories[$name]) ? $this->repositories[$name] : null; }
[ "public", "function", "findRepository", "(", "string", "$", "name", ")", ":", "?", "UserRepository", "{", "return", "isset", "(", "$", "this", "->", "repositories", "[", "$", "name", "]", ")", "?", "$", "this", "->", "repositories", "[", "$", "name", "]", ":", "null", ";", "}" ]
Get repository by name and index. @param string $name @return UserRepository|null
[ "Get", "repository", "by", "name", "and", "index", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/User/UserRepositoryBucket.php#L50-L55
apisearch-io/php-client
Config/SynonymReader.php
SynonymReader.readSynonymsFromFile
public function readSynonymsFromFile(string $filepath): array { if ( !is_file($filepath) || !is_readable($filepath) ) { throw SynonymsException::synonymsFileNotFound($filepath); } $data = file_get_contents($filepath); if (!is_string($data)) { throw SynonymsException::synonymsMalformedData($filepath); } return array_filter(array_map(function ($line) { if (!is_string($line)) { return false; } $words = str_getcsv($line, ','); if (count($words) <= 1) { return false; } return Synonym::createByWords($words); }, str_getcsv($data, "\n"))); }
php
public function readSynonymsFromFile(string $filepath): array { if ( !is_file($filepath) || !is_readable($filepath) ) { throw SynonymsException::synonymsFileNotFound($filepath); } $data = file_get_contents($filepath); if (!is_string($data)) { throw SynonymsException::synonymsMalformedData($filepath); } return array_filter(array_map(function ($line) { if (!is_string($line)) { return false; } $words = str_getcsv($line, ','); if (count($words) <= 1) { return false; } return Synonym::createByWords($words); }, str_getcsv($data, "\n"))); }
[ "public", "function", "readSynonymsFromFile", "(", "string", "$", "filepath", ")", ":", "array", "{", "if", "(", "!", "is_file", "(", "$", "filepath", ")", "||", "!", "is_readable", "(", "$", "filepath", ")", ")", "{", "throw", "SynonymsException", "::", "synonymsFileNotFound", "(", "$", "filepath", ")", ";", "}", "$", "data", "=", "file_get_contents", "(", "$", "filepath", ")", ";", "if", "(", "!", "is_string", "(", "$", "data", ")", ")", "{", "throw", "SynonymsException", "::", "synonymsMalformedData", "(", "$", "filepath", ")", ";", "}", "return", "array_filter", "(", "array_map", "(", "function", "(", "$", "line", ")", "{", "if", "(", "!", "is_string", "(", "$", "line", ")", ")", "{", "return", "false", ";", "}", "$", "words", "=", "str_getcsv", "(", "$", "line", ",", "','", ")", ";", "if", "(", "count", "(", "$", "words", ")", "<=", "1", ")", "{", "return", "false", ";", "}", "return", "Synonym", "::", "createByWords", "(", "$", "words", ")", ";", "}", ",", "str_getcsv", "(", "$", "data", ",", "\"\\n\"", ")", ")", ")", ";", "}" ]
Read synonyms from file. @param string $filepath @return Synonym[] @throws SynonymsException
[ "Read", "synonyms", "from", "file", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Config/SynonymReader.php#L34-L62
apisearch-io/php-client
Config/SynonymReader.php
SynonymReader.readSynonymsFromCommaSeparatedArray
public function readSynonymsFromCommaSeparatedArray(array $synonymsAsCommaSeparatedArray): array { return array_filter(array_map(function (string $line) { if (empty($line)) { return false; } $words = explode(',', $line); if (count($words) <= 1) { return false; } return Synonym::createByWords($words); }, $synonymsAsCommaSeparatedArray)); }
php
public function readSynonymsFromCommaSeparatedArray(array $synonymsAsCommaSeparatedArray): array { return array_filter(array_map(function (string $line) { if (empty($line)) { return false; } $words = explode(',', $line); if (count($words) <= 1) { return false; } return Synonym::createByWords($words); }, $synonymsAsCommaSeparatedArray)); }
[ "public", "function", "readSynonymsFromCommaSeparatedArray", "(", "array", "$", "synonymsAsCommaSeparatedArray", ")", ":", "array", "{", "return", "array_filter", "(", "array_map", "(", "function", "(", "string", "$", "line", ")", "{", "if", "(", "empty", "(", "$", "line", ")", ")", "{", "return", "false", ";", "}", "$", "words", "=", "explode", "(", "','", ",", "$", "line", ")", ";", "if", "(", "count", "(", "$", "words", ")", "<=", "1", ")", "{", "return", "false", ";", "}", "return", "Synonym", "::", "createByWords", "(", "$", "words", ")", ";", "}", ",", "$", "synonymsAsCommaSeparatedArray", ")", ")", ";", "}" ]
Read synonyms from comma separated array. @param array $synonymsAsCommaSeparatedArray @return Synonym[]
[ "Read", "synonyms", "from", "comma", "separated", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Config/SynonymReader.php#L71-L86
apisearch-io/php-client
Repository/DiskRepository.php
DiskRepository.query
public function query( Query $query, array $parameters = [] ): Result { $this->load(); return parent::query($query); }
php
public function query( Query $query, array $parameters = [] ): Result { $this->load(); return parent::query($query); }
[ "public", "function", "query", "(", "Query", "$", "query", ",", "array", "$", "parameters", "=", "[", "]", ")", ":", "Result", "{", "$", "this", "->", "load", "(", ")", ";", "return", "parent", "::", "query", "(", "$", "query", ")", ";", "}" ]
Search across the index types. @param Query $query @param array $parameters @return Result
[ "Search", "across", "the", "index", "types", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/DiskRepository.php#L54-L61
apisearch-io/php-client
Repository/DiskRepository.php
DiskRepository.flushItems
protected function flushItems( array $itemsToUpdate, array $itemsToDelete ) { $this->load(); parent::flushItems( $itemsToUpdate, $itemsToDelete ); $this->save(); }
php
protected function flushItems( array $itemsToUpdate, array $itemsToDelete ) { $this->load(); parent::flushItems( $itemsToUpdate, $itemsToDelete ); $this->save(); }
[ "protected", "function", "flushItems", "(", "array", "$", "itemsToUpdate", ",", "array", "$", "itemsToDelete", ")", "{", "$", "this", "->", "load", "(", ")", ";", "parent", "::", "flushItems", "(", "$", "itemsToUpdate", ",", "$", "itemsToDelete", ")", ";", "$", "this", "->", "save", "(", ")", ";", "}" ]
Flush items. @param Item[] $itemsToUpdate @param ItemUUID[] $itemsToDelete
[ "Flush", "items", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/DiskRepository.php#L81-L91
apisearch-io/php-client
Repository/DiskRepository.php
DiskRepository.load
private function load() { if (!file_exists($this->filename)) { return; } $this->items = unserialize( file_get_contents( $this->filename ) ) ?? []; }
php
private function load() { if (!file_exists($this->filename)) { return; } $this->items = unserialize( file_get_contents( $this->filename ) ) ?? []; }
[ "private", "function", "load", "(", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "filename", ")", ")", "{", "return", ";", "}", "$", "this", "->", "items", "=", "unserialize", "(", "file_get_contents", "(", "$", "this", "->", "filename", ")", ")", "??", "[", "]", ";", "}" ]
Load.
[ "Load", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/DiskRepository.php#L96-L107
apisearch-io/php-client
Repository/HttpRepository.php
HttpRepository.flushItems
protected function flushItems( array $itemsToUpdate, array $itemsToDelete ) { if (!empty($itemsToUpdate)) { $response = $this ->httpClient ->get( sprintf( '/%s/indices/%s/items', $this->getAppUUID()->composeUUID(), $this->getIndexUUID()->composeUUID() ), 'put', [], array_map(function (Item $item) { return $item->toArray(); }, $itemsToUpdate), Http::getApisearchHeaders($this) ); self::throwTransportableExceptionIfNeeded($response); } if (!empty($itemsToDelete)) { $response = $this ->httpClient ->get( sprintf( '/%s/indices/%s/items', $this->getAppUUID()->composeUUID(), $this->getIndexUUID()->composeUUID() ), 'delete', [], array_map(function (ItemUUID $itemUUID) { return $itemUUID->toArray(); }, $itemsToDelete), Http::getApisearchHeaders($this) ); self::throwTransportableExceptionIfNeeded($response); } }
php
protected function flushItems( array $itemsToUpdate, array $itemsToDelete ) { if (!empty($itemsToUpdate)) { $response = $this ->httpClient ->get( sprintf( '/%s/indices/%s/items', $this->getAppUUID()->composeUUID(), $this->getIndexUUID()->composeUUID() ), 'put', [], array_map(function (Item $item) { return $item->toArray(); }, $itemsToUpdate), Http::getApisearchHeaders($this) ); self::throwTransportableExceptionIfNeeded($response); } if (!empty($itemsToDelete)) { $response = $this ->httpClient ->get( sprintf( '/%s/indices/%s/items', $this->getAppUUID()->composeUUID(), $this->getIndexUUID()->composeUUID() ), 'delete', [], array_map(function (ItemUUID $itemUUID) { return $itemUUID->toArray(); }, $itemsToDelete), Http::getApisearchHeaders($this) ); self::throwTransportableExceptionIfNeeded($response); } }
[ "protected", "function", "flushItems", "(", "array", "$", "itemsToUpdate", ",", "array", "$", "itemsToDelete", ")", "{", "if", "(", "!", "empty", "(", "$", "itemsToUpdate", ")", ")", "{", "$", "response", "=", "$", "this", "->", "httpClient", "->", "get", "(", "sprintf", "(", "'/%s/indices/%s/items'", ",", "$", "this", "->", "getAppUUID", "(", ")", "->", "composeUUID", "(", ")", ",", "$", "this", "->", "getIndexUUID", "(", ")", "->", "composeUUID", "(", ")", ")", ",", "'put'", ",", "[", "]", ",", "array_map", "(", "function", "(", "Item", "$", "item", ")", "{", "return", "$", "item", "->", "toArray", "(", ")", ";", "}", ",", "$", "itemsToUpdate", ")", ",", "Http", "::", "getApisearchHeaders", "(", "$", "this", ")", ")", ";", "self", "::", "throwTransportableExceptionIfNeeded", "(", "$", "response", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "itemsToDelete", ")", ")", "{", "$", "response", "=", "$", "this", "->", "httpClient", "->", "get", "(", "sprintf", "(", "'/%s/indices/%s/items'", ",", "$", "this", "->", "getAppUUID", "(", ")", "->", "composeUUID", "(", ")", ",", "$", "this", "->", "getIndexUUID", "(", ")", "->", "composeUUID", "(", ")", ")", ",", "'delete'", ",", "[", "]", ",", "array_map", "(", "function", "(", "ItemUUID", "$", "itemUUID", ")", "{", "return", "$", "itemUUID", "->", "toArray", "(", ")", ";", "}", ",", "$", "itemsToDelete", ")", ",", "Http", "::", "getApisearchHeaders", "(", "$", "this", ")", ")", ";", "self", "::", "throwTransportableExceptionIfNeeded", "(", "$", "response", ")", ";", "}", "}" ]
Flush items. @param Item[] $itemsToUpdate @param ItemUUID[] $itemsToDelete
[ "Flush", "items", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/HttpRepository.php#L59-L102
apisearch-io/php-client
Repository/HttpRepository.php
HttpRepository.updateItems
public function updateItems( Query $query, Changes $changes ) { $response = $this ->httpClient ->get( sprintf( '/%s/indices/%s/items/update-by-query', $this->getAppUUID()->composeUUID(), $this->getIndexUUID()->composeUUID() ), 'post', [], [ Http::QUERY_FIELD => $query->toArray(), Http::CHANGES_FIELD => $changes->toArray(), ], Http::getApisearchHeaders($this) ); self::throwTransportableExceptionIfNeeded($response); }
php
public function updateItems( Query $query, Changes $changes ) { $response = $this ->httpClient ->get( sprintf( '/%s/indices/%s/items/update-by-query', $this->getAppUUID()->composeUUID(), $this->getIndexUUID()->composeUUID() ), 'post', [], [ Http::QUERY_FIELD => $query->toArray(), Http::CHANGES_FIELD => $changes->toArray(), ], Http::getApisearchHeaders($this) ); self::throwTransportableExceptionIfNeeded($response); }
[ "public", "function", "updateItems", "(", "Query", "$", "query", ",", "Changes", "$", "changes", ")", "{", "$", "response", "=", "$", "this", "->", "httpClient", "->", "get", "(", "sprintf", "(", "'/%s/indices/%s/items/update-by-query'", ",", "$", "this", "->", "getAppUUID", "(", ")", "->", "composeUUID", "(", ")", ",", "$", "this", "->", "getIndexUUID", "(", ")", "->", "composeUUID", "(", ")", ")", ",", "'post'", ",", "[", "]", ",", "[", "Http", "::", "QUERY_FIELD", "=>", "$", "query", "->", "toArray", "(", ")", ",", "Http", "::", "CHANGES_FIELD", "=>", "$", "changes", "->", "toArray", "(", ")", ",", "]", ",", "Http", "::", "getApisearchHeaders", "(", "$", "this", ")", ")", ";", "self", "::", "throwTransportableExceptionIfNeeded", "(", "$", "response", ")", ";", "}" ]
Update items. @param Query $query @param Changes $changes
[ "Update", "items", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/HttpRepository.php#L110-L132
apisearch-io/php-client
Repository/HttpRepository.php
HttpRepository.query
public function query( Query $query, array $parameters = [] ): Result { $response = $this ->httpClient ->get( sprintf( '/%s/indices/%s', $this->getAppUUID()->composeUUID(), $this->getIndexUUID()->composeUUID() ), 'get', [ Http::QUERY_FIELD => urlencode(json_encode($query->toArray())), ] + $parameters, [], Http::getApisearchHeaders($this) ); self::throwTransportableExceptionIfNeeded($response); return Result::createFromArray($response['body']); }
php
public function query( Query $query, array $parameters = [] ): Result { $response = $this ->httpClient ->get( sprintf( '/%s/indices/%s', $this->getAppUUID()->composeUUID(), $this->getIndexUUID()->composeUUID() ), 'get', [ Http::QUERY_FIELD => urlencode(json_encode($query->toArray())), ] + $parameters, [], Http::getApisearchHeaders($this) ); self::throwTransportableExceptionIfNeeded($response); return Result::createFromArray($response['body']); }
[ "public", "function", "query", "(", "Query", "$", "query", ",", "array", "$", "parameters", "=", "[", "]", ")", ":", "Result", "{", "$", "response", "=", "$", "this", "->", "httpClient", "->", "get", "(", "sprintf", "(", "'/%s/indices/%s'", ",", "$", "this", "->", "getAppUUID", "(", ")", "->", "composeUUID", "(", ")", ",", "$", "this", "->", "getIndexUUID", "(", ")", "->", "composeUUID", "(", ")", ")", ",", "'get'", ",", "[", "Http", "::", "QUERY_FIELD", "=>", "urlencode", "(", "json_encode", "(", "$", "query", "->", "toArray", "(", ")", ")", ")", ",", "]", "+", "$", "parameters", ",", "[", "]", ",", "Http", "::", "getApisearchHeaders", "(", "$", "this", ")", ")", ";", "self", "::", "throwTransportableExceptionIfNeeded", "(", "$", "response", ")", ";", "return", "Result", "::", "createFromArray", "(", "$", "response", "[", "'body'", "]", ")", ";", "}" ]
Search across the index types. @param Query $query @param array $parameters @return Result
[ "Search", "across", "the", "index", "types", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/HttpRepository.php#L142-L165
apisearch-io/php-client
Query/Aggregation.php
Aggregation.create
public static function create( string $name, string $field, int $applicationType, string $filterType, array $subgroup = [], array $sort = self::SORT_BY_COUNT_DESC, int $limit = self::NO_LIMIT ): self { return new self( $name, $field, $applicationType, $filterType, $subgroup, $sort, $limit ); }
php
public static function create( string $name, string $field, int $applicationType, string $filterType, array $subgroup = [], array $sort = self::SORT_BY_COUNT_DESC, int $limit = self::NO_LIMIT ): self { return new self( $name, $field, $applicationType, $filterType, $subgroup, $sort, $limit ); }
[ "public", "static", "function", "create", "(", "string", "$", "name", ",", "string", "$", "field", ",", "int", "$", "applicationType", ",", "string", "$", "filterType", ",", "array", "$", "subgroup", "=", "[", "]", ",", "array", "$", "sort", "=", "self", "::", "SORT_BY_COUNT_DESC", ",", "int", "$", "limit", "=", "self", "::", "NO_LIMIT", ")", ":", "self", "{", "return", "new", "self", "(", "$", "name", ",", "$", "field", ",", "$", "applicationType", ",", "$", "filterType", ",", "$", "subgroup", ",", "$", "sort", ",", "$", "limit", ")", ";", "}" ]
Create. @param string $name @param string $field @param int $applicationType @param string $filterType @param array $subgroup @param array $sort @param int $limit @return Aggregation
[ "Create", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Aggregation.php#L222-L240
apisearch-io/php-client
Query/Aggregation.php
Aggregation.toArray
public function toArray(): array { return array_filter([ 'name' => $this->name, 'field' => 'uuid.type' === $this->field ? null : $this->field, 'application_type' => Filter::AT_LEAST_ONE === $this->applicationType ? null : $this->applicationType, 'filter_type' => Filter::TYPE_FIELD === $this->filterType ? null : $this->filterType, 'subgroup' => empty($this->subgroup) ? null : $this->subgroup, 'sort' => self::SORT_BY_COUNT_DESC === $this->sort ? null : $this->sort, 'limit' => self::NO_LIMIT === $this->limit ? null : $this->limit, ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
php
public function toArray(): array { return array_filter([ 'name' => $this->name, 'field' => 'uuid.type' === $this->field ? null : $this->field, 'application_type' => Filter::AT_LEAST_ONE === $this->applicationType ? null : $this->applicationType, 'filter_type' => Filter::TYPE_FIELD === $this->filterType ? null : $this->filterType, 'subgroup' => empty($this->subgroup) ? null : $this->subgroup, 'sort' => self::SORT_BY_COUNT_DESC === $this->sort ? null : $this->sort, 'limit' => self::NO_LIMIT === $this->limit ? null : $this->limit, ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "array_filter", "(", "[", "'name'", "=>", "$", "this", "->", "name", ",", "'field'", "=>", "'uuid.type'", "===", "$", "this", "->", "field", "?", "null", ":", "$", "this", "->", "field", ",", "'application_type'", "=>", "Filter", "::", "AT_LEAST_ONE", "===", "$", "this", "->", "applicationType", "?", "null", ":", "$", "this", "->", "applicationType", ",", "'filter_type'", "=>", "Filter", "::", "TYPE_FIELD", "===", "$", "this", "->", "filterType", "?", "null", ":", "$", "this", "->", "filterType", ",", "'subgroup'", "=>", "empty", "(", "$", "this", "->", "subgroup", ")", "?", "null", ":", "$", "this", "->", "subgroup", ",", "'sort'", "=>", "self", "::", "SORT_BY_COUNT_DESC", "===", "$", "this", "->", "sort", "?", "null", ":", "$", "this", "->", "sort", ",", "'limit'", "=>", "self", "::", "NO_LIMIT", "===", "$", "this", "->", "limit", "?", "null", ":", "$", "this", "->", "limit", ",", "]", ",", "function", "(", "$", "element", ")", "{", "return", "!", "(", "is_null", "(", "$", "element", ")", "||", "(", "is_array", "(", "$", "element", ")", "&&", "empty", "(", "$", "element", ")", ")", ")", ";", "}", ")", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Aggregation.php#L247-L276
apisearch-io/php-client
Query/Aggregation.php
Aggregation.createFromArray
public static function createFromArray(array $array): self { if (empty($array['name'])) { throw InvalidFormatException::queryFormatNotValid($array); } return self::create( $array['name'], $array['field'] ?? 'uuid.type', (int) ($array['application_type'] ?? Filter::AT_LEAST_ONE), $array['filter_type'] ?? Filter::TYPE_FIELD, $array['subgroup'] ?? [], $array['sort'] ?? self::SORT_BY_COUNT_DESC, $array['limit'] ?? self::NO_LIMIT ); }
php
public static function createFromArray(array $array): self { if (empty($array['name'])) { throw InvalidFormatException::queryFormatNotValid($array); } return self::create( $array['name'], $array['field'] ?? 'uuid.type', (int) ($array['application_type'] ?? Filter::AT_LEAST_ONE), $array['filter_type'] ?? Filter::TYPE_FIELD, $array['subgroup'] ?? [], $array['sort'] ?? self::SORT_BY_COUNT_DESC, $array['limit'] ?? self::NO_LIMIT ); }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", ":", "self", "{", "if", "(", "empty", "(", "$", "array", "[", "'name'", "]", ")", ")", "{", "throw", "InvalidFormatException", "::", "queryFormatNotValid", "(", "$", "array", ")", ";", "}", "return", "self", "::", "create", "(", "$", "array", "[", "'name'", "]", ",", "$", "array", "[", "'field'", "]", "??", "'uuid.type'", ",", "(", "int", ")", "(", "$", "array", "[", "'application_type'", "]", "??", "Filter", "::", "AT_LEAST_ONE", ")", ",", "$", "array", "[", "'filter_type'", "]", "??", "Filter", "::", "TYPE_FIELD", ",", "$", "array", "[", "'subgroup'", "]", "??", "[", "]", ",", "$", "array", "[", "'sort'", "]", "??", "self", "::", "SORT_BY_COUNT_DESC", ",", "$", "array", "[", "'limit'", "]", "??", "self", "::", "NO_LIMIT", ")", ";", "}" ]
Create from array. @param array $array @return Aggregation
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Aggregation.php#L285-L300
apisearch-io/php-client
App/AppRepositoryBucket.php
AppRepositoryBucket.findRepository
public function findRepository(string $appName): ? AppRepository { return isset($this->repositories[$appName]) ? $this->repositories[$appName] : null; }
php
public function findRepository(string $appName): ? AppRepository { return isset($this->repositories[$appName]) ? $this->repositories[$appName] : null; }
[ "public", "function", "findRepository", "(", "string", "$", "appName", ")", ":", "?", "AppRepository", "{", "return", "isset", "(", "$", "this", "->", "repositories", "[", "$", "appName", "]", ")", "?", "$", "this", "->", "repositories", "[", "$", "appName", "]", ":", "null", ";", "}" ]
Get repository by name and index. @param string $appName @return AppRepository|null
[ "Get", "repository", "by", "name", "and", "index", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/AppRepositoryBucket.php#L67-L72
apisearch-io/php-client
Model/Index.php
Index.toArray
public function toArray(): array { return [ 'uuid' => $this->uuid->toArray(), 'app_id' => $this->appUUID->toArray(), 'is_ok' => $this->isOK, 'doc_count' => $this->docCount, 'size' => $this->size, 'shards' => $this->shards, 'replicas' => $this->replicas, 'fields' => $this->fields, 'metadata' => $this->metadata, ]; }
php
public function toArray(): array { return [ 'uuid' => $this->uuid->toArray(), 'app_id' => $this->appUUID->toArray(), 'is_ok' => $this->isOK, 'doc_count' => $this->docCount, 'size' => $this->size, 'shards' => $this->shards, 'replicas' => $this->replicas, 'fields' => $this->fields, 'metadata' => $this->metadata, ]; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "[", "'uuid'", "=>", "$", "this", "->", "uuid", "->", "toArray", "(", ")", ",", "'app_id'", "=>", "$", "this", "->", "appUUID", "->", "toArray", "(", ")", ",", "'is_ok'", "=>", "$", "this", "->", "isOK", ",", "'doc_count'", "=>", "$", "this", "->", "docCount", ",", "'size'", "=>", "$", "this", "->", "size", ",", "'shards'", "=>", "$", "this", "->", "shards", ",", "'replicas'", "=>", "$", "this", "->", "replicas", ",", "'fields'", "=>", "$", "this", "->", "fields", ",", "'metadata'", "=>", "$", "this", "->", "metadata", ",", "]", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Index.php#L217-L230
apisearch-io/php-client
Model/Index.php
Index.createFromArray
public static function createFromArray(array $array): self { if (!isset($array['uuid'], $array['app_id'])) { throw InvalidFormatException::indexFormatNotValid(); } return new self( IndexUUID::createFromArray($array['uuid']), AppUUID::createFromArray($array['app_id']), $array['is_ok'] ?? false, $array['doc_count'] ?? 0, $array['size'] ?? '0kb', $array['shards'] ?? Config::DEFAULT_SHARDS, $array['replicas'] ?? Config::DEFAULT_REPLICAS, $array['fields'] ?? [], $array['metadata'] ?? [] ); }
php
public static function createFromArray(array $array): self { if (!isset($array['uuid'], $array['app_id'])) { throw InvalidFormatException::indexFormatNotValid(); } return new self( IndexUUID::createFromArray($array['uuid']), AppUUID::createFromArray($array['app_id']), $array['is_ok'] ?? false, $array['doc_count'] ?? 0, $array['size'] ?? '0kb', $array['shards'] ?? Config::DEFAULT_SHARDS, $array['replicas'] ?? Config::DEFAULT_REPLICAS, $array['fields'] ?? [], $array['metadata'] ?? [] ); }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", ":", "self", "{", "if", "(", "!", "isset", "(", "$", "array", "[", "'uuid'", "]", ",", "$", "array", "[", "'app_id'", "]", ")", ")", "{", "throw", "InvalidFormatException", "::", "indexFormatNotValid", "(", ")", ";", "}", "return", "new", "self", "(", "IndexUUID", "::", "createFromArray", "(", "$", "array", "[", "'uuid'", "]", ")", ",", "AppUUID", "::", "createFromArray", "(", "$", "array", "[", "'app_id'", "]", ")", ",", "$", "array", "[", "'is_ok'", "]", "??", "false", ",", "$", "array", "[", "'doc_count'", "]", "??", "0", ",", "$", "array", "[", "'size'", "]", "??", "'0kb'", ",", "$", "array", "[", "'shards'", "]", "??", "Config", "::", "DEFAULT_SHARDS", ",", "$", "array", "[", "'replicas'", "]", "??", "Config", "::", "DEFAULT_REPLICAS", ",", "$", "array", "[", "'fields'", "]", "??", "[", "]", ",", "$", "array", "[", "'metadata'", "]", "??", "[", "]", ")", ";", "}" ]
Create from array. @param array $array @return Index @throws InvalidFormatException
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Index.php#L241-L258
apisearch-io/php-client
Exporter/IndexExporter.php
IndexExporter.importIndex
public function importIndex( Repository $repository, string $data, string $format ) { $items = $this ->exporterCollection ->getExporterByName($format) ->formatToItems($data); $repository->addItems($items); $repository->flush(); }
php
public function importIndex( Repository $repository, string $data, string $format ) { $items = $this ->exporterCollection ->getExporterByName($format) ->formatToItems($data); $repository->addItems($items); $repository->flush(); }
[ "public", "function", "importIndex", "(", "Repository", "$", "repository", ",", "string", "$", "data", ",", "string", "$", "format", ")", "{", "$", "items", "=", "$", "this", "->", "exporterCollection", "->", "getExporterByName", "(", "$", "format", ")", "->", "formatToItems", "(", "$", "data", ")", ";", "$", "repository", "->", "addItems", "(", "$", "items", ")", ";", "$", "repository", "->", "flush", "(", ")", ";", "}" ]
Import index. @param Repository $repository @param string $data @param string $format
[ "Import", "index", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/IndexExporter.php#L50-L62
apisearch-io/php-client
Exporter/IndexExporter.php
IndexExporter.exportIndex
public function exportIndex( Repository $repository, string $format ): string { $allItems = []; $iteration = 0; while (true) { $items = $repository ->query(Query::create('', $iteration, 10000)) ->getItems(); if (empty($items)) { break; } $allItems = array_merge( $allItems, $items ); ++$iteration; } return $this ->exporterCollection ->getExporterByName($format) ->itemsToFormat($allItems); }
php
public function exportIndex( Repository $repository, string $format ): string { $allItems = []; $iteration = 0; while (true) { $items = $repository ->query(Query::create('', $iteration, 10000)) ->getItems(); if (empty($items)) { break; } $allItems = array_merge( $allItems, $items ); ++$iteration; } return $this ->exporterCollection ->getExporterByName($format) ->itemsToFormat($allItems); }
[ "public", "function", "exportIndex", "(", "Repository", "$", "repository", ",", "string", "$", "format", ")", ":", "string", "{", "$", "allItems", "=", "[", "]", ";", "$", "iteration", "=", "0", ";", "while", "(", "true", ")", "{", "$", "items", "=", "$", "repository", "->", "query", "(", "Query", "::", "create", "(", "''", ",", "$", "iteration", ",", "10000", ")", ")", "->", "getItems", "(", ")", ";", "if", "(", "empty", "(", "$", "items", ")", ")", "{", "break", ";", "}", "$", "allItems", "=", "array_merge", "(", "$", "allItems", ",", "$", "items", ")", ";", "++", "$", "iteration", ";", "}", "return", "$", "this", "->", "exporterCollection", "->", "getExporterByName", "(", "$", "format", ")", "->", "itemsToFormat", "(", "$", "allItems", ")", ";", "}" ]
Export index. @param Repository $repository @param string $format @return string
[ "Export", "index", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/IndexExporter.php#L72-L99
apisearch-io/php-client
Config/Config.php
Config.toArray
public function toArray(): array { return array_filter([ 'language' => $this->language, 'store_searchable_metadata' => ($this->storeSearchableMetadata ? null : false), 'synonyms' => array_map(function (Synonym $synonym) { return $synonym->toArray(); }, $this->synonyms), 'shards' => $this->shards, 'replicas' => $this->replicas, ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
php
public function toArray(): array { return array_filter([ 'language' => $this->language, 'store_searchable_metadata' => ($this->storeSearchableMetadata ? null : false), 'synonyms' => array_map(function (Synonym $synonym) { return $synonym->toArray(); }, $this->synonyms), 'shards' => $this->shards, 'replicas' => $this->replicas, ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "array_filter", "(", "[", "'language'", "=>", "$", "this", "->", "language", ",", "'store_searchable_metadata'", "=>", "(", "$", "this", "->", "storeSearchableMetadata", "?", "null", ":", "false", ")", ",", "'synonyms'", "=>", "array_map", "(", "function", "(", "Synonym", "$", "synonym", ")", "{", "return", "$", "synonym", "->", "toArray", "(", ")", ";", "}", ",", "$", "this", "->", "synonyms", ")", ",", "'shards'", "=>", "$", "this", "->", "shards", ",", "'replicas'", "=>", "$", "this", "->", "replicas", ",", "]", ",", "function", "(", "$", "element", ")", "{", "return", "!", "(", "is_null", "(", "$", "element", ")", "||", "(", "is_array", "(", "$", "element", ")", "&&", "empty", "(", "$", "element", ")", ")", ")", ";", "}", ")", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Config/Config.php#L163-L180
apisearch-io/php-client
Config/Config.php
Config.createFromArray
public static function createFromArray(array $array): self { $config = new self( ($array['language'] ?? null), ($array['store_searchable_metadata'] ?? true) ); $config->synonyms = array_map(function (array $synonym) { return Synonym::createFromArray($synonym); }, $array['synonyms'] ?? []); $config->shards = (int) ($array['shards'] ?? self::DEFAULT_SHARDS); $config->replicas = (int) ($array['replicas'] ?? self::DEFAULT_REPLICAS); return $config; }
php
public static function createFromArray(array $array): self { $config = new self( ($array['language'] ?? null), ($array['store_searchable_metadata'] ?? true) ); $config->synonyms = array_map(function (array $synonym) { return Synonym::createFromArray($synonym); }, $array['synonyms'] ?? []); $config->shards = (int) ($array['shards'] ?? self::DEFAULT_SHARDS); $config->replicas = (int) ($array['replicas'] ?? self::DEFAULT_REPLICAS); return $config; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", ":", "self", "{", "$", "config", "=", "new", "self", "(", "(", "$", "array", "[", "'language'", "]", "??", "null", ")", ",", "(", "$", "array", "[", "'store_searchable_metadata'", "]", "??", "true", ")", ")", ";", "$", "config", "->", "synonyms", "=", "array_map", "(", "function", "(", "array", "$", "synonym", ")", "{", "return", "Synonym", "::", "createFromArray", "(", "$", "synonym", ")", ";", "}", ",", "$", "array", "[", "'synonyms'", "]", "??", "[", "]", ")", ";", "$", "config", "->", "shards", "=", "(", "int", ")", "(", "$", "array", "[", "'shards'", "]", "??", "self", "::", "DEFAULT_SHARDS", ")", ";", "$", "config", "->", "replicas", "=", "(", "int", ")", "(", "$", "array", "[", "'replicas'", "]", "??", "self", "::", "DEFAULT_REPLICAS", ")", ";", "return", "$", "config", ";", "}" ]
Create from array. @param array $array @return self
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Config/Config.php#L189-L203
apisearch-io/php-client
Query/Query.php
Query.createLocated
public static function createLocated( Coordinate $coordinate, string $queryText, int $page = self::DEFAULT_PAGE, int $size = self::DEFAULT_SIZE ) { $query = self::create( $queryText, $page, $size ); $query->coordinate = $coordinate; return $query; }
php
public static function createLocated( Coordinate $coordinate, string $queryText, int $page = self::DEFAULT_PAGE, int $size = self::DEFAULT_SIZE ) { $query = self::create( $queryText, $page, $size ); $query->coordinate = $coordinate; return $query; }
[ "public", "static", "function", "createLocated", "(", "Coordinate", "$", "coordinate", ",", "string", "$", "queryText", ",", "int", "$", "page", "=", "self", "::", "DEFAULT_PAGE", ",", "int", "$", "size", "=", "self", "::", "DEFAULT_SIZE", ")", "{", "$", "query", "=", "self", "::", "create", "(", "$", "queryText", ",", "$", "page", ",", "$", "size", ")", ";", "$", "query", "->", "coordinate", "=", "$", "coordinate", ";", "return", "$", "query", ";", "}" ]
Create located Query. @param Coordinate $coordinate @param string $queryText @param int $page @param int $size @return Query
[ "Create", "located", "Query", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L247-L262
apisearch-io/php-client
Query/Query.php
Query.create
public static function create( string $queryText, int $page = self::DEFAULT_PAGE, int $size = self::DEFAULT_SIZE ): self { $page = (int) (max(1, $page)); $query = new self($queryText); $query->from = ($page - 1) * $size; $query->size = $size; $query->page = $page; return $query; }
php
public static function create( string $queryText, int $page = self::DEFAULT_PAGE, int $size = self::DEFAULT_SIZE ): self { $page = (int) (max(1, $page)); $query = new self($queryText); $query->from = ($page - 1) * $size; $query->size = $size; $query->page = $page; return $query; }
[ "public", "static", "function", "create", "(", "string", "$", "queryText", ",", "int", "$", "page", "=", "self", "::", "DEFAULT_PAGE", ",", "int", "$", "size", "=", "self", "::", "DEFAULT_SIZE", ")", ":", "self", "{", "$", "page", "=", "(", "int", ")", "(", "max", "(", "1", ",", "$", "page", ")", ")", ";", "$", "query", "=", "new", "self", "(", "$", "queryText", ")", ";", "$", "query", "->", "from", "=", "(", "$", "page", "-", "1", ")", "*", "$", "size", ";", "$", "query", "->", "size", "=", "$", "size", ";", "$", "query", "->", "page", "=", "$", "page", ";", "return", "$", "query", ";", "}" ]
Create new. @param string $queryText @param int $page @param int $size @return Query
[ "Create", "new", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L273-L285
apisearch-io/php-client
Query/Query.php
Query.createByUUIDs
public static function createByUUIDs(array $uuids): self { $ids = array_map(function (ItemUUID $uuid) { return $uuid->composeUUID(); }, $uuids); $query = self::create('', self::DEFAULT_PAGE, count($uuids)) ->disableAggregations() ->disableSuggestions(); $query->filters['_id'] = Filter::create( '_id', array_unique($ids), Filter::AT_LEAST_ONE, Filter::TYPE_FIELD ); return $query; }
php
public static function createByUUIDs(array $uuids): self { $ids = array_map(function (ItemUUID $uuid) { return $uuid->composeUUID(); }, $uuids); $query = self::create('', self::DEFAULT_PAGE, count($uuids)) ->disableAggregations() ->disableSuggestions(); $query->filters['_id'] = Filter::create( '_id', array_unique($ids), Filter::AT_LEAST_ONE, Filter::TYPE_FIELD ); return $query; }
[ "public", "static", "function", "createByUUIDs", "(", "array", "$", "uuids", ")", ":", "self", "{", "$", "ids", "=", "array_map", "(", "function", "(", "ItemUUID", "$", "uuid", ")", "{", "return", "$", "uuid", "->", "composeUUID", "(", ")", ";", "}", ",", "$", "uuids", ")", ";", "$", "query", "=", "self", "::", "create", "(", "''", ",", "self", "::", "DEFAULT_PAGE", ",", "count", "(", "$", "uuids", ")", ")", "->", "disableAggregations", "(", ")", "->", "disableSuggestions", "(", ")", ";", "$", "query", "->", "filters", "[", "'_id'", "]", "=", "Filter", "::", "create", "(", "'_id'", ",", "array_unique", "(", "$", "ids", ")", ",", "Filter", "::", "AT_LEAST_ONE", ",", "Filter", "::", "TYPE_FIELD", ")", ";", "return", "$", "query", ";", "}" ]
Create by references. @param ItemUUID[] $uuids @return Query
[ "Create", "by", "references", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L320-L338
apisearch-io/php-client
Query/Query.php
Query.filterUniverseByTypes
public function filterUniverseByTypes(array $values): self { $fieldPath = Item::getPathByField('type'); if (!empty($values)) { $this->universeFilters['type'] = Filter::create( $fieldPath, $values, Filter::AT_LEAST_ONE, Filter::TYPE_FIELD ); } else { unset($this->universeFilters['type']); } return $this; }
php
public function filterUniverseByTypes(array $values): self { $fieldPath = Item::getPathByField('type'); if (!empty($values)) { $this->universeFilters['type'] = Filter::create( $fieldPath, $values, Filter::AT_LEAST_ONE, Filter::TYPE_FIELD ); } else { unset($this->universeFilters['type']); } return $this; }
[ "public", "function", "filterUniverseByTypes", "(", "array", "$", "values", ")", ":", "self", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "'type'", ")", ";", "if", "(", "!", "empty", "(", "$", "values", ")", ")", "{", "$", "this", "->", "universeFilters", "[", "'type'", "]", "=", "Filter", "::", "create", "(", "$", "fieldPath", ",", "$", "values", ",", "Filter", "::", "AT_LEAST_ONE", ",", "Filter", "::", "TYPE_FIELD", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "universeFilters", "[", "'type'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Filter universe by types. @param array $values @return Query
[ "Filter", "universe", "by", "types", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L386-L401
apisearch-io/php-client
Query/Query.php
Query.filterByTypes
public function filterByTypes( array $values, bool $aggregate = true, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC ): self { $fieldPath = Item::getPathByField('type'); if (!empty($values)) { $this->filters['type'] = Filter::create( $fieldPath, $values, Filter::AT_LEAST_ONE, Filter::TYPE_FIELD ); } else { unset($this->filters['type']); } if ($aggregate) { $this->aggregations['type'] = Aggregation::create( 'type', $fieldPath, Filter::AT_LEAST_ONE, Filter::TYPE_FIELD, [], $aggregationSort ); } return $this; }
php
public function filterByTypes( array $values, bool $aggregate = true, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC ): self { $fieldPath = Item::getPathByField('type'); if (!empty($values)) { $this->filters['type'] = Filter::create( $fieldPath, $values, Filter::AT_LEAST_ONE, Filter::TYPE_FIELD ); } else { unset($this->filters['type']); } if ($aggregate) { $this->aggregations['type'] = Aggregation::create( 'type', $fieldPath, Filter::AT_LEAST_ONE, Filter::TYPE_FIELD, [], $aggregationSort ); } return $this; }
[ "public", "function", "filterByTypes", "(", "array", "$", "values", ",", "bool", "$", "aggregate", "=", "true", ",", "array", "$", "aggregationSort", "=", "Aggregation", "::", "SORT_BY_COUNT_DESC", ")", ":", "self", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "'type'", ")", ";", "if", "(", "!", "empty", "(", "$", "values", ")", ")", "{", "$", "this", "->", "filters", "[", "'type'", "]", "=", "Filter", "::", "create", "(", "$", "fieldPath", ",", "$", "values", ",", "Filter", "::", "AT_LEAST_ONE", ",", "Filter", "::", "TYPE_FIELD", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "filters", "[", "'type'", "]", ")", ";", "}", "if", "(", "$", "aggregate", ")", "{", "$", "this", "->", "aggregations", "[", "'type'", "]", "=", "Aggregation", "::", "create", "(", "'type'", ",", "$", "fieldPath", ",", "Filter", "::", "AT_LEAST_ONE", ",", "Filter", "::", "TYPE_FIELD", ",", "[", "]", ",", "$", "aggregationSort", ")", ";", "}", "return", "$", "this", ";", "}" ]
Filter by types. @param array $values @param bool $aggregate @param array $aggregationSort @return Query
[ "Filter", "by", "types", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L412-L441
apisearch-io/php-client
Query/Query.php
Query.filterByIds
public function filterByIds(array $values): self { $fieldPath = Item::getPathByField('id'); if (!empty($values)) { $this->filters['id'] = Filter::create( $fieldPath, $values, Filter::AT_LEAST_ONE, Filter::TYPE_FIELD ); } else { unset($this->filters['id']); } return $this; }
php
public function filterByIds(array $values): self { $fieldPath = Item::getPathByField('id'); if (!empty($values)) { $this->filters['id'] = Filter::create( $fieldPath, $values, Filter::AT_LEAST_ONE, Filter::TYPE_FIELD ); } else { unset($this->filters['id']); } return $this; }
[ "public", "function", "filterByIds", "(", "array", "$", "values", ")", ":", "self", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "'id'", ")", ";", "if", "(", "!", "empty", "(", "$", "values", ")", ")", "{", "$", "this", "->", "filters", "[", "'id'", "]", "=", "Filter", "::", "create", "(", "$", "fieldPath", ",", "$", "values", ",", "Filter", "::", "AT_LEAST_ONE", ",", "Filter", "::", "TYPE_FIELD", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "filters", "[", "'id'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Filter by types. @param array $values @return Query
[ "Filter", "by", "types", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L474-L489
apisearch-io/php-client
Query/Query.php
Query.filterUniverseBy
public function filterUniverseBy( string $field, array $values, int $applicationType = Filter::AT_LEAST_ONE ): self { $fieldPath = Item::getPathByField($field); if (!empty($values)) { $this->universeFilters[$field] = Filter::create( $fieldPath, $values, $applicationType, Filter::TYPE_FIELD ); } else { unset($this->universeFilters[$field]); } return $this; }
php
public function filterUniverseBy( string $field, array $values, int $applicationType = Filter::AT_LEAST_ONE ): self { $fieldPath = Item::getPathByField($field); if (!empty($values)) { $this->universeFilters[$field] = Filter::create( $fieldPath, $values, $applicationType, Filter::TYPE_FIELD ); } else { unset($this->universeFilters[$field]); } return $this; }
[ "public", "function", "filterUniverseBy", "(", "string", "$", "field", ",", "array", "$", "values", ",", "int", "$", "applicationType", "=", "Filter", "::", "AT_LEAST_ONE", ")", ":", "self", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "$", "field", ")", ";", "if", "(", "!", "empty", "(", "$", "values", ")", ")", "{", "$", "this", "->", "universeFilters", "[", "$", "field", "]", "=", "Filter", "::", "create", "(", "$", "fieldPath", ",", "$", "values", ",", "$", "applicationType", ",", "Filter", "::", "TYPE_FIELD", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "universeFilters", "[", "$", "field", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Filter universe by. @param string $field @param array $values @param int $applicationType @return Query
[ "Filter", "universe", "by", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L500-L518
apisearch-io/php-client
Query/Query.php
Query.filterBy
public function filterBy( string $filterName, string $field, array $values, int $applicationType = Filter::AT_LEAST_ONE, bool $aggregate = true, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC ): self { $fieldPath = Item::getPathByField($field); if (!empty($values)) { $this->filters[$filterName] = Filter::create( $fieldPath, $values, $applicationType, Filter::TYPE_FIELD ); } else { unset($this->filters[$filterName]); } if ($aggregate) { $this->aggregateBy( $filterName, $field, $applicationType, $aggregationSort ); } return $this; }
php
public function filterBy( string $filterName, string $field, array $values, int $applicationType = Filter::AT_LEAST_ONE, bool $aggregate = true, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC ): self { $fieldPath = Item::getPathByField($field); if (!empty($values)) { $this->filters[$filterName] = Filter::create( $fieldPath, $values, $applicationType, Filter::TYPE_FIELD ); } else { unset($this->filters[$filterName]); } if ($aggregate) { $this->aggregateBy( $filterName, $field, $applicationType, $aggregationSort ); } return $this; }
[ "public", "function", "filterBy", "(", "string", "$", "filterName", ",", "string", "$", "field", ",", "array", "$", "values", ",", "int", "$", "applicationType", "=", "Filter", "::", "AT_LEAST_ONE", ",", "bool", "$", "aggregate", "=", "true", ",", "array", "$", "aggregationSort", "=", "Aggregation", "::", "SORT_BY_COUNT_DESC", ")", ":", "self", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "$", "field", ")", ";", "if", "(", "!", "empty", "(", "$", "values", ")", ")", "{", "$", "this", "->", "filters", "[", "$", "filterName", "]", "=", "Filter", "::", "create", "(", "$", "fieldPath", ",", "$", "values", ",", "$", "applicationType", ",", "Filter", "::", "TYPE_FIELD", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "filters", "[", "$", "filterName", "]", ")", ";", "}", "if", "(", "$", "aggregate", ")", "{", "$", "this", "->", "aggregateBy", "(", "$", "filterName", ",", "$", "field", ",", "$", "applicationType", ",", "$", "aggregationSort", ")", ";", "}", "return", "$", "this", ";", "}" ]
Filter by. @param string $filterName @param string $field @param array $values @param int $applicationType @param bool $aggregate @param array $aggregationSort @return Query
[ "Filter", "by", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L532-L562
apisearch-io/php-client
Query/Query.php
Query.filterUniverseByRange
public function filterUniverseByRange( string $field, array $values, int $applicationType = Filter::AT_LEAST_ONE, string $rangeType = Filter::TYPE_RANGE ): self { $fieldPath = Item::getPathByField($field); if (!empty($values)) { $this->universeFilters[$field] = Filter::create( $fieldPath, $values, $applicationType, $rangeType ); } else { unset($this->universeFilters[$field]); } return $this; }
php
public function filterUniverseByRange( string $field, array $values, int $applicationType = Filter::AT_LEAST_ONE, string $rangeType = Filter::TYPE_RANGE ): self { $fieldPath = Item::getPathByField($field); if (!empty($values)) { $this->universeFilters[$field] = Filter::create( $fieldPath, $values, $applicationType, $rangeType ); } else { unset($this->universeFilters[$field]); } return $this; }
[ "public", "function", "filterUniverseByRange", "(", "string", "$", "field", ",", "array", "$", "values", ",", "int", "$", "applicationType", "=", "Filter", "::", "AT_LEAST_ONE", ",", "string", "$", "rangeType", "=", "Filter", "::", "TYPE_RANGE", ")", ":", "self", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "$", "field", ")", ";", "if", "(", "!", "empty", "(", "$", "values", ")", ")", "{", "$", "this", "->", "universeFilters", "[", "$", "field", "]", "=", "Filter", "::", "create", "(", "$", "fieldPath", ",", "$", "values", ",", "$", "applicationType", ",", "$", "rangeType", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "universeFilters", "[", "$", "field", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Filter universe by range. @param string $field @param array $values @param int $applicationType @param string $rangeType @return Query
[ "Filter", "universe", "by", "range", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L574-L593
apisearch-io/php-client
Query/Query.php
Query.filterUniverseByDateRange
public function filterUniverseByDateRange( string $field, array $values, int $applicationType = Filter::AT_LEAST_ONE ): self { return $this->filterUniverseByRange( $field, $values, $applicationType, Filter::TYPE_DATE_RANGE ); }
php
public function filterUniverseByDateRange( string $field, array $values, int $applicationType = Filter::AT_LEAST_ONE ): self { return $this->filterUniverseByRange( $field, $values, $applicationType, Filter::TYPE_DATE_RANGE ); }
[ "public", "function", "filterUniverseByDateRange", "(", "string", "$", "field", ",", "array", "$", "values", ",", "int", "$", "applicationType", "=", "Filter", "::", "AT_LEAST_ONE", ")", ":", "self", "{", "return", "$", "this", "->", "filterUniverseByRange", "(", "$", "field", ",", "$", "values", ",", "$", "applicationType", ",", "Filter", "::", "TYPE_DATE_RANGE", ")", ";", "}" ]
Filter universe by range. @param string $field @param array $values @param int $applicationType @return Query
[ "Filter", "universe", "by", "range", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L604-L615
apisearch-io/php-client
Query/Query.php
Query.filterByRange
public function filterByRange( string $filterName, string $field, array $options, array $values, int $applicationType = Filter::AT_LEAST_ONE, string $rangeType = Filter::TYPE_RANGE, bool $aggregate = true, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC ): self { $fieldPath = Item::getPathByField($field); if (!empty($values)) { $this->filters[$filterName] = Filter::create( $fieldPath, $values, $applicationType, $rangeType ); } else { unset($this->filters[$filterName]); } if ($aggregate) { $this->aggregateByRange( $filterName, $fieldPath, $options, $applicationType, $rangeType, $aggregationSort ); } return $this; }
php
public function filterByRange( string $filterName, string $field, array $options, array $values, int $applicationType = Filter::AT_LEAST_ONE, string $rangeType = Filter::TYPE_RANGE, bool $aggregate = true, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC ): self { $fieldPath = Item::getPathByField($field); if (!empty($values)) { $this->filters[$filterName] = Filter::create( $fieldPath, $values, $applicationType, $rangeType ); } else { unset($this->filters[$filterName]); } if ($aggregate) { $this->aggregateByRange( $filterName, $fieldPath, $options, $applicationType, $rangeType, $aggregationSort ); } return $this; }
[ "public", "function", "filterByRange", "(", "string", "$", "filterName", ",", "string", "$", "field", ",", "array", "$", "options", ",", "array", "$", "values", ",", "int", "$", "applicationType", "=", "Filter", "::", "AT_LEAST_ONE", ",", "string", "$", "rangeType", "=", "Filter", "::", "TYPE_RANGE", ",", "bool", "$", "aggregate", "=", "true", ",", "array", "$", "aggregationSort", "=", "Aggregation", "::", "SORT_BY_COUNT_DESC", ")", ":", "self", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "$", "field", ")", ";", "if", "(", "!", "empty", "(", "$", "values", ")", ")", "{", "$", "this", "->", "filters", "[", "$", "filterName", "]", "=", "Filter", "::", "create", "(", "$", "fieldPath", ",", "$", "values", ",", "$", "applicationType", ",", "$", "rangeType", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "filters", "[", "$", "filterName", "]", ")", ";", "}", "if", "(", "$", "aggregate", ")", "{", "$", "this", "->", "aggregateByRange", "(", "$", "filterName", ",", "$", "fieldPath", ",", "$", "options", ",", "$", "applicationType", ",", "$", "rangeType", ",", "$", "aggregationSort", ")", ";", "}", "return", "$", "this", ";", "}" ]
Filter by range. @param string $filterName @param string $field @param array $options @param array $values @param int $applicationType @param string $rangeType @param bool $aggregate @param array $aggregationSort @return Query
[ "Filter", "by", "range", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L631-L665
apisearch-io/php-client
Query/Query.php
Query.filterByDateRange
public function filterByDateRange( string $filterName, string $field, array $options, array $values, int $applicationType = Filter::AT_LEAST_ONE, bool $aggregate = true, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC ): self { return $this->filterByRange( $filterName, $field, $options, $values, $applicationType, Filter::TYPE_DATE_RANGE, $aggregate, $aggregationSort ); }
php
public function filterByDateRange( string $filterName, string $field, array $options, array $values, int $applicationType = Filter::AT_LEAST_ONE, bool $aggregate = true, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC ): self { return $this->filterByRange( $filterName, $field, $options, $values, $applicationType, Filter::TYPE_DATE_RANGE, $aggregate, $aggregationSort ); }
[ "public", "function", "filterByDateRange", "(", "string", "$", "filterName", ",", "string", "$", "field", ",", "array", "$", "options", ",", "array", "$", "values", ",", "int", "$", "applicationType", "=", "Filter", "::", "AT_LEAST_ONE", ",", "bool", "$", "aggregate", "=", "true", ",", "array", "$", "aggregationSort", "=", "Aggregation", "::", "SORT_BY_COUNT_DESC", ")", ":", "self", "{", "return", "$", "this", "->", "filterByRange", "(", "$", "filterName", ",", "$", "field", ",", "$", "options", ",", "$", "values", ",", "$", "applicationType", ",", "Filter", "::", "TYPE_DATE_RANGE", ",", "$", "aggregate", ",", "$", "aggregationSort", ")", ";", "}" ]
Filter by range. @param string $filterName @param string $field @param array $options @param array $values @param int $applicationType @param bool $aggregate @param array $aggregationSort @return Query
[ "Filter", "by", "range", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L680-L699
apisearch-io/php-client
Query/Query.php
Query.filterUniverseByLocation
public function filterUniverseByLocation(LocationRange $locationRange): self { $this->universeFilters['coordinate'] = Filter::create( 'coordinate', $locationRange->toArray(), Filter::AT_LEAST_ONE, Filter::TYPE_GEO ); return $this; }
php
public function filterUniverseByLocation(LocationRange $locationRange): self { $this->universeFilters['coordinate'] = Filter::create( 'coordinate', $locationRange->toArray(), Filter::AT_LEAST_ONE, Filter::TYPE_GEO ); return $this; }
[ "public", "function", "filterUniverseByLocation", "(", "LocationRange", "$", "locationRange", ")", ":", "self", "{", "$", "this", "->", "universeFilters", "[", "'coordinate'", "]", "=", "Filter", "::", "create", "(", "'coordinate'", ",", "$", "locationRange", "->", "toArray", "(", ")", ",", "Filter", "::", "AT_LEAST_ONE", ",", "Filter", "::", "TYPE_GEO", ")", ";", "return", "$", "this", ";", "}" ]
Filter universe by location. @param LocationRange $locationRange @return Query
[ "Filter", "universe", "by", "location", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L708-L718
apisearch-io/php-client
Query/Query.php
Query.sortBy
public function sortBy(SortBy $sortBy): self { if ($sortBy->isSortedByGeoDistance()) { if (!$this->coordinate instanceof Coordinate) { throw InvalidFormatException::querySortedByDistanceWithoutCoordinate(); } $sortBy->setCoordinate($this->coordinate); } $this->sortBy = $sortBy; return $this; }
php
public function sortBy(SortBy $sortBy): self { if ($sortBy->isSortedByGeoDistance()) { if (!$this->coordinate instanceof Coordinate) { throw InvalidFormatException::querySortedByDistanceWithoutCoordinate(); } $sortBy->setCoordinate($this->coordinate); } $this->sortBy = $sortBy; return $this; }
[ "public", "function", "sortBy", "(", "SortBy", "$", "sortBy", ")", ":", "self", "{", "if", "(", "$", "sortBy", "->", "isSortedByGeoDistance", "(", ")", ")", "{", "if", "(", "!", "$", "this", "->", "coordinate", "instanceof", "Coordinate", ")", "{", "throw", "InvalidFormatException", "::", "querySortedByDistanceWithoutCoordinate", "(", ")", ";", "}", "$", "sortBy", "->", "setCoordinate", "(", "$", "this", "->", "coordinate", ")", ";", "}", "$", "this", "->", "sortBy", "=", "$", "sortBy", ";", "return", "$", "this", ";", "}" ]
Sort by. @param SortBy $sortBy @return Query
[ "Sort", "by", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L751-L764
apisearch-io/php-client
Query/Query.php
Query.aggregateBy
public function aggregateBy( string $filterName, string $field, int $applicationType, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC, int $limit = Aggregation::NO_LIMIT ): self { $this->aggregations[$filterName] = Aggregation::create( $filterName, Item::getPathByField($field), $applicationType, Filter::TYPE_FIELD, [], $aggregationSort, $limit ); return $this; }
php
public function aggregateBy( string $filterName, string $field, int $applicationType, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC, int $limit = Aggregation::NO_LIMIT ): self { $this->aggregations[$filterName] = Aggregation::create( $filterName, Item::getPathByField($field), $applicationType, Filter::TYPE_FIELD, [], $aggregationSort, $limit ); return $this; }
[ "public", "function", "aggregateBy", "(", "string", "$", "filterName", ",", "string", "$", "field", ",", "int", "$", "applicationType", ",", "array", "$", "aggregationSort", "=", "Aggregation", "::", "SORT_BY_COUNT_DESC", ",", "int", "$", "limit", "=", "Aggregation", "::", "NO_LIMIT", ")", ":", "self", "{", "$", "this", "->", "aggregations", "[", "$", "filterName", "]", "=", "Aggregation", "::", "create", "(", "$", "filterName", ",", "Item", "::", "getPathByField", "(", "$", "field", ")", ",", "$", "applicationType", ",", "Filter", "::", "TYPE_FIELD", ",", "[", "]", ",", "$", "aggregationSort", ",", "$", "limit", ")", ";", "return", "$", "this", ";", "}" ]
Add Families aggregation. @param string $filterName @param string $field @param int $applicationType @param array $aggregationSort @param int $limit @return Query
[ "Add", "Families", "aggregation", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L777-L795
apisearch-io/php-client
Query/Query.php
Query.aggregateByRange
public function aggregateByRange( string $filterName, string $field, array $options, int $applicationType, string $rangeType = Filter::TYPE_RANGE, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC, int $limit = Aggregation::NO_LIMIT ): self { if (empty($options)) { return $this; } $this->aggregations[$filterName] = Aggregation::create( $filterName, Item::getPathByField($field), $applicationType, $rangeType, $options, $aggregationSort, $limit ); return $this; }
php
public function aggregateByRange( string $filterName, string $field, array $options, int $applicationType, string $rangeType = Filter::TYPE_RANGE, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC, int $limit = Aggregation::NO_LIMIT ): self { if (empty($options)) { return $this; } $this->aggregations[$filterName] = Aggregation::create( $filterName, Item::getPathByField($field), $applicationType, $rangeType, $options, $aggregationSort, $limit ); return $this; }
[ "public", "function", "aggregateByRange", "(", "string", "$", "filterName", ",", "string", "$", "field", ",", "array", "$", "options", ",", "int", "$", "applicationType", ",", "string", "$", "rangeType", "=", "Filter", "::", "TYPE_RANGE", ",", "array", "$", "aggregationSort", "=", "Aggregation", "::", "SORT_BY_COUNT_DESC", ",", "int", "$", "limit", "=", "Aggregation", "::", "NO_LIMIT", ")", ":", "self", "{", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "aggregations", "[", "$", "filterName", "]", "=", "Aggregation", "::", "create", "(", "$", "filterName", ",", "Item", "::", "getPathByField", "(", "$", "field", ")", ",", "$", "applicationType", ",", "$", "rangeType", ",", "$", "options", ",", "$", "aggregationSort", ",", "$", "limit", ")", ";", "return", "$", "this", ";", "}" ]
Add tags aggregation. @param string $filterName @param string $field @param array $options @param int $applicationType @param string $rangeType @param array $aggregationSort @param int $limit @return Query
[ "Add", "tags", "aggregation", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L810-L834
apisearch-io/php-client
Query/Query.php
Query.aggregateByDateRange
public function aggregateByDateRange( string $filterName, string $field, array $options, int $applicationType, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC, int $limit = Aggregation::NO_LIMIT ): self { if (empty($options)) { return $this; } $this->aggregations[$filterName] = Aggregation::create( $filterName, Item::getPathByField($field), $applicationType, Filter::TYPE_DATE_RANGE, $options, $aggregationSort, $limit ); return $this; }
php
public function aggregateByDateRange( string $filterName, string $field, array $options, int $applicationType, array $aggregationSort = Aggregation::SORT_BY_COUNT_DESC, int $limit = Aggregation::NO_LIMIT ): self { if (empty($options)) { return $this; } $this->aggregations[$filterName] = Aggregation::create( $filterName, Item::getPathByField($field), $applicationType, Filter::TYPE_DATE_RANGE, $options, $aggregationSort, $limit ); return $this; }
[ "public", "function", "aggregateByDateRange", "(", "string", "$", "filterName", ",", "string", "$", "field", ",", "array", "$", "options", ",", "int", "$", "applicationType", ",", "array", "$", "aggregationSort", "=", "Aggregation", "::", "SORT_BY_COUNT_DESC", ",", "int", "$", "limit", "=", "Aggregation", "::", "NO_LIMIT", ")", ":", "self", "{", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "aggregations", "[", "$", "filterName", "]", "=", "Aggregation", "::", "create", "(", "$", "filterName", ",", "Item", "::", "getPathByField", "(", "$", "field", ")", ",", "$", "applicationType", ",", "Filter", "::", "TYPE_DATE_RANGE", ",", "$", "options", ",", "$", "aggregationSort", ",", "$", "limit", ")", ";", "return", "$", "this", ";", "}" ]
Add tags aggregation. @param string $filterName @param string $field @param array $options @param int $applicationType @param array $aggregationSort @param int $limit @return Query
[ "Add", "tags", "aggregation", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L848-L871
apisearch-io/php-client
Query/Query.php
Query.getQueryText
public function getQueryText(): string { return ( isset($this->filters['_query']) && $this->filters['_query'] instanceof Filter ) ? $this->filters['_query']->getValues()[0] : ''; }
php
public function getQueryText(): string { return ( isset($this->filters['_query']) && $this->filters['_query'] instanceof Filter ) ? $this->filters['_query']->getValues()[0] : ''; }
[ "public", "function", "getQueryText", "(", ")", ":", "string", "{", "return", "(", "isset", "(", "$", "this", "->", "filters", "[", "'_query'", "]", ")", "&&", "$", "this", "->", "filters", "[", "'_query'", "]", "instanceof", "Filter", ")", "?", "$", "this", "->", "filters", "[", "'_query'", "]", "->", "getValues", "(", ")", "[", "0", "]", ":", "''", ";", "}" ]
Return Querytext. @return string
[ "Return", "Querytext", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L900-L908
apisearch-io/php-client
Query/Query.php
Query.getFilterByField
public function getFilterByField(string $fieldName): ? Filter { $fieldPath = Item::getPathByField($fieldName); foreach ($this->getFilters() as $filter) { if ($fieldPath === $filter->getField()) { return $filter; } } return null; }
php
public function getFilterByField(string $fieldName): ? Filter { $fieldPath = Item::getPathByField($fieldName); foreach ($this->getFilters() as $filter) { if ($fieldPath === $filter->getField()) { return $filter; } } return null; }
[ "public", "function", "getFilterByField", "(", "string", "$", "fieldName", ")", ":", "?", "Filter", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "$", "fieldName", ")", ";", "foreach", "(", "$", "this", "->", "getFilters", "(", ")", "as", "$", "filter", ")", "{", "if", "(", "$", "fieldPath", "===", "$", "filter", "->", "getField", "(", ")", ")", "{", "return", "$", "filter", ";", "}", "}", "return", "null", ";", "}" ]
Get filter. @param string $fieldName @return Filter|null
[ "Get", "filter", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L961-L971
apisearch-io/php-client
Query/Query.php
Query.excludeUUIDs
public function excludeUUIDs(array $uuids): self { $this->filters['excluded_ids'] = Filter::create( '_id', array_map(function (ItemUUID $uuid) { return $uuid->composeUUID(); }, $uuids), Filter::EXCLUDE, Filter::TYPE_FIELD ); return $this; }
php
public function excludeUUIDs(array $uuids): self { $this->filters['excluded_ids'] = Filter::create( '_id', array_map(function (ItemUUID $uuid) { return $uuid->composeUUID(); }, $uuids), Filter::EXCLUDE, Filter::TYPE_FIELD ); return $this; }
[ "public", "function", "excludeUUIDs", "(", "array", "$", "uuids", ")", ":", "self", "{", "$", "this", "->", "filters", "[", "'excluded_ids'", "]", "=", "Filter", "::", "create", "(", "'_id'", ",", "array_map", "(", "function", "(", "ItemUUID", "$", "uuid", ")", "{", "return", "$", "uuid", "->", "composeUUID", "(", ")", ";", "}", ",", "$", "uuids", ")", ",", "Filter", "::", "EXCLUDE", ",", "Filter", "::", "TYPE_FIELD", ")", ";", "return", "$", "this", ";", "}" ]
Exclude reference. @param ItemUUID[] $uuids @return Query
[ "Exclude", "reference", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L1194-L1206
apisearch-io/php-client
Query/Query.php
Query.setMetadataValue
public function setMetadataValue( string $name, $value ): self { $this->metadata[$name] = $value; return $this; }
php
public function setMetadataValue( string $name, $value ): self { $this->metadata[$name] = $value; return $this; }
[ "public", "function", "setMetadataValue", "(", "string", "$", "name", ",", "$", "value", ")", ":", "self", "{", "$", "this", "->", "metadata", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set metadata. @param string $name @param mixed $value @return Query
[ "Set", "metadata", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L1350-L1357
apisearch-io/php-client
Query/Query.php
Query.addSubQuery
public function addSubQuery( string $name, Query $query ): self { $this->subqueries[$name] = $query; return $this; }
php
public function addSubQuery( string $name, Query $query ): self { $this->subqueries[$name] = $query; return $this; }
[ "public", "function", "addSubQuery", "(", "string", "$", "name", ",", "Query", "$", "query", ")", ":", "self", "{", "$", "this", "->", "subqueries", "[", "$", "name", "]", "=", "$", "query", ";", "return", "$", "this", ";", "}" ]
Add subquery. @param string $name @param Query $query @return Query
[ "Add", "subquery", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L1377-L1384
apisearch-io/php-client
Query/Query.php
Query.toArray
public function toArray(): array { return array_filter([ 'uuid' => $this->UUID, 'q' => '' !== $this->getQueryText() ? $this->getQueryText() : null, 'fields' => $this->getFields(), 'coordinate' => $this->coordinate instanceof HttpTransportable ? $this->coordinate->toArray() : null, 'filters' => array_filter( array_map(function (Filter $filter) { return Filter::TYPE_QUERY !== $filter->getFilterType() ? $filter->toArray() : null; }, $this->filters) ), 'universe_filters' => array_filter( array_map(function (Filter $filter) { return $filter->toArray(); }, $this->universeFilters) ), 'aggregations' => array_map(function (Aggregation $aggregation) { return $aggregation->toArray(); }, $this->aggregations), 'sort' => $this->sortBy instanceof SortBy ? $this->sortBy->toArray() : null, 'page' => self::DEFAULT_PAGE === $this->page ? null : $this->page, 'size' => self::DEFAULT_SIZE === $this->size ? null : $this->size, 'results_enabled' => $this->resultsEnabled ? null : false, 'suggestions_enabled' => $this->suggestionsEnabled ?: null, 'highlight_enabled' => $this->highlightEnabled ?: null, 'aggregations_enabled' => $this->aggregationsEnabled ? null : false, 'searchable_fields' => $this->searchableFields, 'score_strategies' => $this->scoreStrategies instanceof ScoreStrategies ? $this->scoreStrategies->toArray() : null, 'fuzziness' => $this->fuzziness, 'min_score' => ($this->minScore > self::NO_MIN_SCORE) ? $this->minScore : null, 'user' => ($this->user instanceof User) ? $this->user->toArray() : null, 'metadata' => $this->metadata, 'subqueries' => array_map(function (Query $query) { return $query->toArray(); }, $this->subqueries), 'items_promoted' => array_filter( array_map(function (ItemUUID $itemUUID) { return $itemUUID->toArray(); }, $this->itemsPromoted) ), 'index_uuid' => ($this->indexUUID instanceof IndexUUID) ? $this->indexUUID->toArray() : null, ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
php
public function toArray(): array { return array_filter([ 'uuid' => $this->UUID, 'q' => '' !== $this->getQueryText() ? $this->getQueryText() : null, 'fields' => $this->getFields(), 'coordinate' => $this->coordinate instanceof HttpTransportable ? $this->coordinate->toArray() : null, 'filters' => array_filter( array_map(function (Filter $filter) { return Filter::TYPE_QUERY !== $filter->getFilterType() ? $filter->toArray() : null; }, $this->filters) ), 'universe_filters' => array_filter( array_map(function (Filter $filter) { return $filter->toArray(); }, $this->universeFilters) ), 'aggregations' => array_map(function (Aggregation $aggregation) { return $aggregation->toArray(); }, $this->aggregations), 'sort' => $this->sortBy instanceof SortBy ? $this->sortBy->toArray() : null, 'page' => self::DEFAULT_PAGE === $this->page ? null : $this->page, 'size' => self::DEFAULT_SIZE === $this->size ? null : $this->size, 'results_enabled' => $this->resultsEnabled ? null : false, 'suggestions_enabled' => $this->suggestionsEnabled ?: null, 'highlight_enabled' => $this->highlightEnabled ?: null, 'aggregations_enabled' => $this->aggregationsEnabled ? null : false, 'searchable_fields' => $this->searchableFields, 'score_strategies' => $this->scoreStrategies instanceof ScoreStrategies ? $this->scoreStrategies->toArray() : null, 'fuzziness' => $this->fuzziness, 'min_score' => ($this->minScore > self::NO_MIN_SCORE) ? $this->minScore : null, 'user' => ($this->user instanceof User) ? $this->user->toArray() : null, 'metadata' => $this->metadata, 'subqueries' => array_map(function (Query $query) { return $query->toArray(); }, $this->subqueries), 'items_promoted' => array_filter( array_map(function (ItemUUID $itemUUID) { return $itemUUID->toArray(); }, $this->itemsPromoted) ), 'index_uuid' => ($this->indexUUID instanceof IndexUUID) ? $this->indexUUID->toArray() : null, ], function ($element) { return !( is_null($element) || (is_array($element) && empty($element)) ); }); }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "array_filter", "(", "[", "'uuid'", "=>", "$", "this", "->", "UUID", ",", "'q'", "=>", "''", "!==", "$", "this", "->", "getQueryText", "(", ")", "?", "$", "this", "->", "getQueryText", "(", ")", ":", "null", ",", "'fields'", "=>", "$", "this", "->", "getFields", "(", ")", ",", "'coordinate'", "=>", "$", "this", "->", "coordinate", "instanceof", "HttpTransportable", "?", "$", "this", "->", "coordinate", "->", "toArray", "(", ")", ":", "null", ",", "'filters'", "=>", "array_filter", "(", "array_map", "(", "function", "(", "Filter", "$", "filter", ")", "{", "return", "Filter", "::", "TYPE_QUERY", "!==", "$", "filter", "->", "getFilterType", "(", ")", "?", "$", "filter", "->", "toArray", "(", ")", ":", "null", ";", "}", ",", "$", "this", "->", "filters", ")", ")", ",", "'universe_filters'", "=>", "array_filter", "(", "array_map", "(", "function", "(", "Filter", "$", "filter", ")", "{", "return", "$", "filter", "->", "toArray", "(", ")", ";", "}", ",", "$", "this", "->", "universeFilters", ")", ")", ",", "'aggregations'", "=>", "array_map", "(", "function", "(", "Aggregation", "$", "aggregation", ")", "{", "return", "$", "aggregation", "->", "toArray", "(", ")", ";", "}", ",", "$", "this", "->", "aggregations", ")", ",", "'sort'", "=>", "$", "this", "->", "sortBy", "instanceof", "SortBy", "?", "$", "this", "->", "sortBy", "->", "toArray", "(", ")", ":", "null", ",", "'page'", "=>", "self", "::", "DEFAULT_PAGE", "===", "$", "this", "->", "page", "?", "null", ":", "$", "this", "->", "page", ",", "'size'", "=>", "self", "::", "DEFAULT_SIZE", "===", "$", "this", "->", "size", "?", "null", ":", "$", "this", "->", "size", ",", "'results_enabled'", "=>", "$", "this", "->", "resultsEnabled", "?", "null", ":", "false", ",", "'suggestions_enabled'", "=>", "$", "this", "->", "suggestionsEnabled", "?", ":", "null", ",", "'highlight_enabled'", "=>", "$", "this", "->", "highlightEnabled", "?", ":", "null", ",", "'aggregations_enabled'", "=>", "$", "this", "->", "aggregationsEnabled", "?", "null", ":", "false", ",", "'searchable_fields'", "=>", "$", "this", "->", "searchableFields", ",", "'score_strategies'", "=>", "$", "this", "->", "scoreStrategies", "instanceof", "ScoreStrategies", "?", "$", "this", "->", "scoreStrategies", "->", "toArray", "(", ")", ":", "null", ",", "'fuzziness'", "=>", "$", "this", "->", "fuzziness", ",", "'min_score'", "=>", "(", "$", "this", "->", "minScore", ">", "self", "::", "NO_MIN_SCORE", ")", "?", "$", "this", "->", "minScore", ":", "null", ",", "'user'", "=>", "(", "$", "this", "->", "user", "instanceof", "User", ")", "?", "$", "this", "->", "user", "->", "toArray", "(", ")", ":", "null", ",", "'metadata'", "=>", "$", "this", "->", "metadata", ",", "'subqueries'", "=>", "array_map", "(", "function", "(", "Query", "$", "query", ")", "{", "return", "$", "query", "->", "toArray", "(", ")", ";", "}", ",", "$", "this", "->", "subqueries", ")", ",", "'items_promoted'", "=>", "array_filter", "(", "array_map", "(", "function", "(", "ItemUUID", "$", "itemUUID", ")", "{", "return", "$", "itemUUID", "->", "toArray", "(", ")", ";", "}", ",", "$", "this", "->", "itemsPromoted", ")", ")", ",", "'index_uuid'", "=>", "(", "$", "this", "->", "indexUUID", "instanceof", "IndexUUID", ")", "?", "$", "this", "->", "indexUUID", "->", "toArray", "(", ")", ":", "null", ",", "]", ",", "function", "(", "$", "element", ")", "{", "return", "!", "(", "is_null", "(", "$", "element", ")", "||", "(", "is_array", "(", "$", "element", ")", "&&", "empty", "(", "$", "element", ")", ")", ")", ";", "}", ")", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L1449-L1522
apisearch-io/php-client
Query/Query.php
Query.createFromArray
public static function createFromArray(array $array): self { $query = isset($array['coordinate']) ? self::createLocated( Coordinate::createFromArray($array['coordinate']), $array['q'] ?? '', (int) ($array['page'] ?? self::DEFAULT_PAGE), (int) ($array['size'] ?? self::DEFAULT_SIZE) ) : self::create( $array['q'] ?? '', (int) ($array['page'] ?? self::DEFAULT_PAGE), (int) ($array['size'] ?? self::DEFAULT_SIZE) ); $query->fields = $array['fields'] ?? []; $query->aggregations = array_map(function (array $aggregation) { return Aggregation::createFromArray($aggregation); }, $array['aggregations'] ?? []); $query->sortBy = SortBy::createFromArray($array['sort'] ?? []); $query->filters = array_merge( $query->filters, array_map(function (array $filter) { return Filter::createFromArray($filter); }, $array['filters'] ?? []) ); $query->universeFilters = array_merge( $query->universeFilters, array_map(function (array $filter) { return Filter::createFromArray($filter); }, $array['universe_filters'] ?? []) ); $query->resultsEnabled = $array['results_enabled'] ?? true; $query->suggestionsEnabled = $array['suggestions_enabled'] ?? false; $query->aggregationsEnabled = $array['aggregations_enabled'] ?? true; $query->highlightEnabled = $array['highlight_enabled'] ?? false; $query->itemsPromoted = array_values(array_map(function (array $itemUUID) { return ItemUUID::createFromArray($itemUUID); }, $array['items_promoted'] ?? [])); $query->fuzziness = $array['fuzziness'] ?? null; $query->searchableFields = $array['searchable_fields'] ?? []; $query->scoreStrategies = isset($array['score_strategies']) ? ScoreStrategies::createFromArray($array['score_strategies']) : null; $query->minScore = $array['min_score'] ?? self::NO_MIN_SCORE; $query->metadata = $array['metadata'] ?? []; if (isset($array['user'])) { $query->user = User::createFromArray($array['user']); } $query->subqueries = array_map(function (array $query) { return Query::createFromArray($query); }, $array['subqueries'] ?? []); if (isset($array['uuid'])) { $query->UUID = $array['uuid']; } if (isset($array['index_uuid'])) { $query->indexUUID = IndexUUID::createFromArray($array['index_uuid']); } return $query; }
php
public static function createFromArray(array $array): self { $query = isset($array['coordinate']) ? self::createLocated( Coordinate::createFromArray($array['coordinate']), $array['q'] ?? '', (int) ($array['page'] ?? self::DEFAULT_PAGE), (int) ($array['size'] ?? self::DEFAULT_SIZE) ) : self::create( $array['q'] ?? '', (int) ($array['page'] ?? self::DEFAULT_PAGE), (int) ($array['size'] ?? self::DEFAULT_SIZE) ); $query->fields = $array['fields'] ?? []; $query->aggregations = array_map(function (array $aggregation) { return Aggregation::createFromArray($aggregation); }, $array['aggregations'] ?? []); $query->sortBy = SortBy::createFromArray($array['sort'] ?? []); $query->filters = array_merge( $query->filters, array_map(function (array $filter) { return Filter::createFromArray($filter); }, $array['filters'] ?? []) ); $query->universeFilters = array_merge( $query->universeFilters, array_map(function (array $filter) { return Filter::createFromArray($filter); }, $array['universe_filters'] ?? []) ); $query->resultsEnabled = $array['results_enabled'] ?? true; $query->suggestionsEnabled = $array['suggestions_enabled'] ?? false; $query->aggregationsEnabled = $array['aggregations_enabled'] ?? true; $query->highlightEnabled = $array['highlight_enabled'] ?? false; $query->itemsPromoted = array_values(array_map(function (array $itemUUID) { return ItemUUID::createFromArray($itemUUID); }, $array['items_promoted'] ?? [])); $query->fuzziness = $array['fuzziness'] ?? null; $query->searchableFields = $array['searchable_fields'] ?? []; $query->scoreStrategies = isset($array['score_strategies']) ? ScoreStrategies::createFromArray($array['score_strategies']) : null; $query->minScore = $array['min_score'] ?? self::NO_MIN_SCORE; $query->metadata = $array['metadata'] ?? []; if (isset($array['user'])) { $query->user = User::createFromArray($array['user']); } $query->subqueries = array_map(function (array $query) { return Query::createFromArray($query); }, $array['subqueries'] ?? []); if (isset($array['uuid'])) { $query->UUID = $array['uuid']; } if (isset($array['index_uuid'])) { $query->indexUUID = IndexUUID::createFromArray($array['index_uuid']); } return $query; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", ":", "self", "{", "$", "query", "=", "isset", "(", "$", "array", "[", "'coordinate'", "]", ")", "?", "self", "::", "createLocated", "(", "Coordinate", "::", "createFromArray", "(", "$", "array", "[", "'coordinate'", "]", ")", ",", "$", "array", "[", "'q'", "]", "??", "''", ",", "(", "int", ")", "(", "$", "array", "[", "'page'", "]", "??", "self", "::", "DEFAULT_PAGE", ")", ",", "(", "int", ")", "(", "$", "array", "[", "'size'", "]", "??", "self", "::", "DEFAULT_SIZE", ")", ")", ":", "self", "::", "create", "(", "$", "array", "[", "'q'", "]", "??", "''", ",", "(", "int", ")", "(", "$", "array", "[", "'page'", "]", "??", "self", "::", "DEFAULT_PAGE", ")", ",", "(", "int", ")", "(", "$", "array", "[", "'size'", "]", "??", "self", "::", "DEFAULT_SIZE", ")", ")", ";", "$", "query", "->", "fields", "=", "$", "array", "[", "'fields'", "]", "??", "[", "]", ";", "$", "query", "->", "aggregations", "=", "array_map", "(", "function", "(", "array", "$", "aggregation", ")", "{", "return", "Aggregation", "::", "createFromArray", "(", "$", "aggregation", ")", ";", "}", ",", "$", "array", "[", "'aggregations'", "]", "??", "[", "]", ")", ";", "$", "query", "->", "sortBy", "=", "SortBy", "::", "createFromArray", "(", "$", "array", "[", "'sort'", "]", "??", "[", "]", ")", ";", "$", "query", "->", "filters", "=", "array_merge", "(", "$", "query", "->", "filters", ",", "array_map", "(", "function", "(", "array", "$", "filter", ")", "{", "return", "Filter", "::", "createFromArray", "(", "$", "filter", ")", ";", "}", ",", "$", "array", "[", "'filters'", "]", "??", "[", "]", ")", ")", ";", "$", "query", "->", "universeFilters", "=", "array_merge", "(", "$", "query", "->", "universeFilters", ",", "array_map", "(", "function", "(", "array", "$", "filter", ")", "{", "return", "Filter", "::", "createFromArray", "(", "$", "filter", ")", ";", "}", ",", "$", "array", "[", "'universe_filters'", "]", "??", "[", "]", ")", ")", ";", "$", "query", "->", "resultsEnabled", "=", "$", "array", "[", "'results_enabled'", "]", "??", "true", ";", "$", "query", "->", "suggestionsEnabled", "=", "$", "array", "[", "'suggestions_enabled'", "]", "??", "false", ";", "$", "query", "->", "aggregationsEnabled", "=", "$", "array", "[", "'aggregations_enabled'", "]", "??", "true", ";", "$", "query", "->", "highlightEnabled", "=", "$", "array", "[", "'highlight_enabled'", "]", "??", "false", ";", "$", "query", "->", "itemsPromoted", "=", "array_values", "(", "array_map", "(", "function", "(", "array", "$", "itemUUID", ")", "{", "return", "ItemUUID", "::", "createFromArray", "(", "$", "itemUUID", ")", ";", "}", ",", "$", "array", "[", "'items_promoted'", "]", "??", "[", "]", ")", ")", ";", "$", "query", "->", "fuzziness", "=", "$", "array", "[", "'fuzziness'", "]", "??", "null", ";", "$", "query", "->", "searchableFields", "=", "$", "array", "[", "'searchable_fields'", "]", "??", "[", "]", ";", "$", "query", "->", "scoreStrategies", "=", "isset", "(", "$", "array", "[", "'score_strategies'", "]", ")", "?", "ScoreStrategies", "::", "createFromArray", "(", "$", "array", "[", "'score_strategies'", "]", ")", ":", "null", ";", "$", "query", "->", "minScore", "=", "$", "array", "[", "'min_score'", "]", "??", "self", "::", "NO_MIN_SCORE", ";", "$", "query", "->", "metadata", "=", "$", "array", "[", "'metadata'", "]", "??", "[", "]", ";", "if", "(", "isset", "(", "$", "array", "[", "'user'", "]", ")", ")", "{", "$", "query", "->", "user", "=", "User", "::", "createFromArray", "(", "$", "array", "[", "'user'", "]", ")", ";", "}", "$", "query", "->", "subqueries", "=", "array_map", "(", "function", "(", "array", "$", "query", ")", "{", "return", "Query", "::", "createFromArray", "(", "$", "query", ")", ";", "}", ",", "$", "array", "[", "'subqueries'", "]", "??", "[", "]", ")", ";", "if", "(", "isset", "(", "$", "array", "[", "'uuid'", "]", ")", ")", "{", "$", "query", "->", "UUID", "=", "$", "array", "[", "'uuid'", "]", ";", "}", "if", "(", "isset", "(", "$", "array", "[", "'index_uuid'", "]", ")", ")", "{", "$", "query", "->", "indexUUID", "=", "IndexUUID", "::", "createFromArray", "(", "$", "array", "[", "'index_uuid'", "]", ")", ";", "}", "return", "$", "query", ";", "}" ]
Create from array. @param array $array @return Query
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Query.php#L1531-L1594
apisearch-io/php-client
Http/HttpResponsesToException.php
HttpResponsesToException.throwTransportableExceptionIfNeeded
protected static function throwTransportableExceptionIfNeeded( array $response, string $url = '' ) { if ( !isset($response['code']) || 0 === $response['code'] ) { throw ConnectionException::buildConnectExceptionByUrl($url); } switch ($response['code']) { case ResourceNotAvailableException::getTransportableHTTPError(): throw new ResourceNotAvailableException($response['body']['message']); case InvalidTokenException::getTransportableHTTPError(): throw new InvalidTokenException($response['body']['message']); case InvalidFormatException::getTransportableHTTPError(): throw new InvalidFormatException($response['body']['message']); case ResourceExistsException::getTransportableHTTPError(): throw new ResourceExistsException($response['body']['message']); case ForbiddenException::getTransportableHTTPError(): throw new ForbiddenException($response['body']['message']); case ConnectionException::getTransportableHTTPError(): throw new ConnectionException('Apisearch returned an internal error code [500]'); } }
php
protected static function throwTransportableExceptionIfNeeded( array $response, string $url = '' ) { if ( !isset($response['code']) || 0 === $response['code'] ) { throw ConnectionException::buildConnectExceptionByUrl($url); } switch ($response['code']) { case ResourceNotAvailableException::getTransportableHTTPError(): throw new ResourceNotAvailableException($response['body']['message']); case InvalidTokenException::getTransportableHTTPError(): throw new InvalidTokenException($response['body']['message']); case InvalidFormatException::getTransportableHTTPError(): throw new InvalidFormatException($response['body']['message']); case ResourceExistsException::getTransportableHTTPError(): throw new ResourceExistsException($response['body']['message']); case ForbiddenException::getTransportableHTTPError(): throw new ForbiddenException($response['body']['message']); case ConnectionException::getTransportableHTTPError(): throw new ConnectionException('Apisearch returned an internal error code [500]'); } }
[ "protected", "static", "function", "throwTransportableExceptionIfNeeded", "(", "array", "$", "response", ",", "string", "$", "url", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "response", "[", "'code'", "]", ")", "||", "0", "===", "$", "response", "[", "'code'", "]", ")", "{", "throw", "ConnectionException", "::", "buildConnectExceptionByUrl", "(", "$", "url", ")", ";", "}", "switch", "(", "$", "response", "[", "'code'", "]", ")", "{", "case", "ResourceNotAvailableException", "::", "getTransportableHTTPError", "(", ")", ":", "throw", "new", "ResourceNotAvailableException", "(", "$", "response", "[", "'body'", "]", "[", "'message'", "]", ")", ";", "case", "InvalidTokenException", "::", "getTransportableHTTPError", "(", ")", ":", "throw", "new", "InvalidTokenException", "(", "$", "response", "[", "'body'", "]", "[", "'message'", "]", ")", ";", "case", "InvalidFormatException", "::", "getTransportableHTTPError", "(", ")", ":", "throw", "new", "InvalidFormatException", "(", "$", "response", "[", "'body'", "]", "[", "'message'", "]", ")", ";", "case", "ResourceExistsException", "::", "getTransportableHTTPError", "(", ")", ":", "throw", "new", "ResourceExistsException", "(", "$", "response", "[", "'body'", "]", "[", "'message'", "]", ")", ";", "case", "ForbiddenException", "::", "getTransportableHTTPError", "(", ")", ":", "throw", "new", "ForbiddenException", "(", "$", "response", "[", "'body'", "]", "[", "'message'", "]", ")", ";", "case", "ConnectionException", "::", "getTransportableHTTPError", "(", ")", ":", "throw", "new", "ConnectionException", "(", "'Apisearch returned an internal error code [500]'", ")", ";", "}", "}" ]
Transform transportable http errors to exceptions. @param array $response @param string $url @throw TransportableException
[ "Transform", "transportable", "http", "errors", "to", "exceptions", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/HttpResponsesToException.php#L38-L63
apisearch-io/php-client
Transformer/Transformer.php
Transformer.fromItems
public function fromItems(array $items): array { $objects = []; foreach ($items as $item) { $objects[] = $this->fromItem($item); } return $objects; }
php
public function fromItems(array $items): array { $objects = []; foreach ($items as $item) { $objects[] = $this->fromItem($item); } return $objects; }
[ "public", "function", "fromItems", "(", "array", "$", "items", ")", ":", "array", "{", "$", "objects", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "objects", "[", "]", "=", "$", "this", "->", "fromItem", "(", "$", "item", ")", ";", "}", "return", "$", "objects", ";", "}" ]
Transform a set of items into a set of objects. @param Item[] $items @return array
[ "Transform", "a", "set", "of", "items", "into", "a", "set", "of", "objects", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Transformer/Transformer.php#L85-L93
apisearch-io/php-client
Transformer/Transformer.php
Transformer.fromItem
public function fromItem(Item $item) { foreach ($this->readTransformers as $readTransformer) { if ($readTransformer->isValidItem($item)) { return $readTransformer->fromItem($item); } } return $item; }
php
public function fromItem(Item $item) { foreach ($this->readTransformers as $readTransformer) { if ($readTransformer->isValidItem($item)) { return $readTransformer->fromItem($item); } } return $item; }
[ "public", "function", "fromItem", "(", "Item", "$", "item", ")", "{", "foreach", "(", "$", "this", "->", "readTransformers", "as", "$", "readTransformer", ")", "{", "if", "(", "$", "readTransformer", "->", "isValidItem", "(", "$", "item", ")", ")", "{", "return", "$", "readTransformer", "->", "fromItem", "(", "$", "item", ")", ";", "}", "}", "return", "$", "item", ";", "}" ]
Transform an item into an object. @param Item $item @return mixed
[ "Transform", "an", "item", "into", "an", "object", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Transformer/Transformer.php#L102-L111
apisearch-io/php-client
Transformer/Transformer.php
Transformer.toItems
public function toItems(array $objects): array { $items = []; foreach ($objects as $object) { $item = $this->toItem($object); if ($item instanceof Item) { $items[] = $item; } } return $items; }
php
public function toItems(array $objects): array { $items = []; foreach ($objects as $object) { $item = $this->toItem($object); if ($item instanceof Item) { $items[] = $item; } } return $items; }
[ "public", "function", "toItems", "(", "array", "$", "objects", ")", ":", "array", "{", "$", "items", "=", "[", "]", ";", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "$", "item", "=", "$", "this", "->", "toItem", "(", "$", "object", ")", ";", "if", "(", "$", "item", "instanceof", "Item", ")", "{", "$", "items", "[", "]", "=", "$", "item", ";", "}", "}", "return", "$", "items", ";", "}" ]
Transform a set of objects into a set of items. @param array $objects @return Item[]
[ "Transform", "a", "set", "of", "objects", "into", "a", "set", "of", "items", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Transformer/Transformer.php#L120-L131
apisearch-io/php-client
Transformer/Transformer.php
Transformer.toItem
public function toItem($object): ? Item { foreach ($this->writeTransformers as $writeTransformer) { if ($writeTransformer->isValidObject($object)) { $item = $writeTransformer->toItem($object); $this ->eventDispatcher ->dispatch( 'apisearch.item_transformed', new ItemTransformed( $item, $object ) ); return $item; } } return null; }
php
public function toItem($object): ? Item { foreach ($this->writeTransformers as $writeTransformer) { if ($writeTransformer->isValidObject($object)) { $item = $writeTransformer->toItem($object); $this ->eventDispatcher ->dispatch( 'apisearch.item_transformed', new ItemTransformed( $item, $object ) ); return $item; } } return null; }
[ "public", "function", "toItem", "(", "$", "object", ")", ":", "?", "Item", "{", "foreach", "(", "$", "this", "->", "writeTransformers", "as", "$", "writeTransformer", ")", "{", "if", "(", "$", "writeTransformer", "->", "isValidObject", "(", "$", "object", ")", ")", "{", "$", "item", "=", "$", "writeTransformer", "->", "toItem", "(", "$", "object", ")", ";", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "'apisearch.item_transformed'", ",", "new", "ItemTransformed", "(", "$", "item", ",", "$", "object", ")", ")", ";", "return", "$", "item", ";", "}", "}", "return", "null", ";", "}" ]
Transform an object into an item. @param mixed $object @return Item|null
[ "Transform", "an", "object", "into", "an", "item", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Transformer/Transformer.php#L140-L160
apisearch-io/php-client
Transformer/Transformer.php
Transformer.toItemUUIDs
public function toItemUUIDs(array $objects): array { $itemUUIDs = []; foreach ($objects as $object) { $itemUUID = $this->toItemUUID($object); if ($itemUUID instanceof ItemUUID) { $itemUUIDs[] = $itemUUID; } } return $itemUUIDs; }
php
public function toItemUUIDs(array $objects): array { $itemUUIDs = []; foreach ($objects as $object) { $itemUUID = $this->toItemUUID($object); if ($itemUUID instanceof ItemUUID) { $itemUUIDs[] = $itemUUID; } } return $itemUUIDs; }
[ "public", "function", "toItemUUIDs", "(", "array", "$", "objects", ")", ":", "array", "{", "$", "itemUUIDs", "=", "[", "]", ";", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "$", "itemUUID", "=", "$", "this", "->", "toItemUUID", "(", "$", "object", ")", ";", "if", "(", "$", "itemUUID", "instanceof", "ItemUUID", ")", "{", "$", "itemUUIDs", "[", "]", "=", "$", "itemUUID", ";", "}", "}", "return", "$", "itemUUIDs", ";", "}" ]
Transform a set of objects into a set of itemUUIDs. @param array $objects @return ItemUUID[]
[ "Transform", "a", "set", "of", "objects", "into", "a", "set", "of", "itemUUIDs", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Transformer/Transformer.php#L169-L180
apisearch-io/php-client
Transformer/Transformer.php
Transformer.toItemUUID
public function toItemUUID($object): ? ItemUUID { foreach ($this->writeTransformers as $writeTransformer) { if ($writeTransformer->isValidObject($object)) { return $writeTransformer->toItemUUID($object); } } return null; }
php
public function toItemUUID($object): ? ItemUUID { foreach ($this->writeTransformers as $writeTransformer) { if ($writeTransformer->isValidObject($object)) { return $writeTransformer->toItemUUID($object); } } return null; }
[ "public", "function", "toItemUUID", "(", "$", "object", ")", ":", "?", "ItemUUID", "{", "foreach", "(", "$", "this", "->", "writeTransformers", "as", "$", "writeTransformer", ")", "{", "if", "(", "$", "writeTransformer", "->", "isValidObject", "(", "$", "object", ")", ")", "{", "return", "$", "writeTransformer", "->", "toItemUUID", "(", "$", "object", ")", ";", "}", "}", "return", "null", ";", "}" ]
Transform an object into an itemUUID or return NULL if the object is not transformable. @param mixed $object @return ItemUUID|null
[ "Transform", "an", "object", "into", "an", "itemUUID", "or", "return", "NULL", "if", "the", "object", "is", "not", "transformable", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Transformer/Transformer.php#L190-L199
apisearch-io/php-client
Query/SortBy.php
SortBy.byFieldsValues
public static function byFieldsValues(array $shortSortByElements): SortBy { $sortBy = self::create(); foreach ($shortSortByElements as $field => $order) { $sortBy->byFieldValue($field, $order); } return $sortBy; }
php
public static function byFieldsValues(array $shortSortByElements): SortBy { $sortBy = self::create(); foreach ($shortSortByElements as $field => $order) { $sortBy->byFieldValue($field, $order); } return $sortBy; }
[ "public", "static", "function", "byFieldsValues", "(", "array", "$", "shortSortByElements", ")", ":", "SortBy", "{", "$", "sortBy", "=", "self", "::", "create", "(", ")", ";", "foreach", "(", "$", "shortSortByElements", "as", "$", "field", "=>", "$", "order", ")", "{", "$", "sortBy", "->", "byFieldValue", "(", "$", "field", ",", "$", "order", ")", ";", "}", "return", "$", "sortBy", ";", "}" ]
Create sort by with passed simple fields and values. SortBy::byFieldsValues([ ['brand' => 'asc'], ['category' => 'desc'], ]); @param array $shortSortByElements @return SortBy
[ "Create", "sort", "by", "with", "passed", "simple", "fields", "and", "values", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L233-L241
apisearch-io/php-client
Query/SortBy.php
SortBy.byValue
public function byValue(array $value): SortBy { if ( self::SCORE !== $value && self::RANDOM !== $value ) { $value['type'] = $value['type'] ?? self::TYPE_FIELD; } $this->sortsBy[] = $value; return $this; }
php
public function byValue(array $value): SortBy { if ( self::SCORE !== $value && self::RANDOM !== $value ) { $value['type'] = $value['type'] ?? self::TYPE_FIELD; } $this->sortsBy[] = $value; return $this; }
[ "public", "function", "byValue", "(", "array", "$", "value", ")", ":", "SortBy", "{", "if", "(", "self", "::", "SCORE", "!==", "$", "value", "&&", "self", "::", "RANDOM", "!==", "$", "value", ")", "{", "$", "value", "[", "'type'", "]", "=", "$", "value", "[", "'type'", "]", "??", "self", "::", "TYPE_FIELD", ";", "}", "$", "this", "->", "sortsBy", "[", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Sort by value. @param array $value @return SortBy
[ "Sort", "by", "value", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L262-L274
apisearch-io/php-client
Query/SortBy.php
SortBy.byFieldValue
public function byFieldValue( string $field, string $order ): SortBy { $this->sortsBy[] = [ 'type' => self::TYPE_FIELD, 'field' => Item::getPathByField($field), 'order' => $order, ]; return $this; }
php
public function byFieldValue( string $field, string $order ): SortBy { $this->sortsBy[] = [ 'type' => self::TYPE_FIELD, 'field' => Item::getPathByField($field), 'order' => $order, ]; return $this; }
[ "public", "function", "byFieldValue", "(", "string", "$", "field", ",", "string", "$", "order", ")", ":", "SortBy", "{", "$", "this", "->", "sortsBy", "[", "]", "=", "[", "'type'", "=>", "self", "::", "TYPE_FIELD", ",", "'field'", "=>", "Item", "::", "getPathByField", "(", "$", "field", ")", ",", "'order'", "=>", "$", "order", ",", "]", ";", "return", "$", "this", ";", "}" ]
Sort by field. @param string $field @param string $order @return SortBy
[ "Sort", "by", "field", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L284-L295
apisearch-io/php-client
Query/SortBy.php
SortBy.byNestedField
public function byNestedField( string $field, string $order, string $mode = self::MODE_AVG ): SortBy { $this->sortsBy[] = [ 'type' => self::TYPE_NESTED, 'mode' => $mode, 'field' => "indexed_metadata.$field", 'order' => $order, ]; return $this; }
php
public function byNestedField( string $field, string $order, string $mode = self::MODE_AVG ): SortBy { $this->sortsBy[] = [ 'type' => self::TYPE_NESTED, 'mode' => $mode, 'field' => "indexed_metadata.$field", 'order' => $order, ]; return $this; }
[ "public", "function", "byNestedField", "(", "string", "$", "field", ",", "string", "$", "order", ",", "string", "$", "mode", "=", "self", "::", "MODE_AVG", ")", ":", "SortBy", "{", "$", "this", "->", "sortsBy", "[", "]", "=", "[", "'type'", "=>", "self", "::", "TYPE_NESTED", ",", "'mode'", "=>", "$", "mode", ",", "'field'", "=>", "\"indexed_metadata.$field\"", ",", "'order'", "=>", "$", "order", ",", "]", ";", "return", "$", "this", ";", "}" ]
Sort by nested field and filter. @param string $field @param string $order @param string $mode @return SortBy
[ "Sort", "by", "nested", "field", "and", "filter", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L306-L319
apisearch-io/php-client
Query/SortBy.php
SortBy.byNestedFieldAndFilter
public function byNestedFieldAndFilter( string $field, string $order, Filter $filter, string $mode = self::MODE_AVG ): SortBy { $fieldPath = Item::getPathByField($filter->getField()); $filterAsArray = $filter->toArray(); $filterAsArray['field'] = $fieldPath; $filter = Filter::createFromArray($filterAsArray); $this->sortsBy[] = [ 'type' => self::TYPE_NESTED, 'filter' => $filter, 'mode' => $mode, 'field' => "indexed_metadata.$field", 'order' => $order, ]; return $this; }
php
public function byNestedFieldAndFilter( string $field, string $order, Filter $filter, string $mode = self::MODE_AVG ): SortBy { $fieldPath = Item::getPathByField($filter->getField()); $filterAsArray = $filter->toArray(); $filterAsArray['field'] = $fieldPath; $filter = Filter::createFromArray($filterAsArray); $this->sortsBy[] = [ 'type' => self::TYPE_NESTED, 'filter' => $filter, 'mode' => $mode, 'field' => "indexed_metadata.$field", 'order' => $order, ]; return $this; }
[ "public", "function", "byNestedFieldAndFilter", "(", "string", "$", "field", ",", "string", "$", "order", ",", "Filter", "$", "filter", ",", "string", "$", "mode", "=", "self", "::", "MODE_AVG", ")", ":", "SortBy", "{", "$", "fieldPath", "=", "Item", "::", "getPathByField", "(", "$", "filter", "->", "getField", "(", ")", ")", ";", "$", "filterAsArray", "=", "$", "filter", "->", "toArray", "(", ")", ";", "$", "filterAsArray", "[", "'field'", "]", "=", "$", "fieldPath", ";", "$", "filter", "=", "Filter", "::", "createFromArray", "(", "$", "filterAsArray", ")", ";", "$", "this", "->", "sortsBy", "[", "]", "=", "[", "'type'", "=>", "self", "::", "TYPE_NESTED", ",", "'filter'", "=>", "$", "filter", ",", "'mode'", "=>", "$", "mode", ",", "'field'", "=>", "\"indexed_metadata.$field\"", ",", "'order'", "=>", "$", "order", ",", "]", ";", "return", "$", "this", ";", "}" ]
Sort by nested field and filter. @param string $field @param string $order @param Filter $filter @param string $mode @return SortBy
[ "Sort", "by", "nested", "field", "and", "filter", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L331-L350
apisearch-io/php-client
Query/SortBy.php
SortBy.byFunction
public function byFunction( string $function, string $order ): SortBy { $this->sortsBy[] = [ 'type' => self::TYPE_FUNCTION, 'function' => $function, 'order' => $order, ]; return $this; }
php
public function byFunction( string $function, string $order ): SortBy { $this->sortsBy[] = [ 'type' => self::TYPE_FUNCTION, 'function' => $function, 'order' => $order, ]; return $this; }
[ "public", "function", "byFunction", "(", "string", "$", "function", ",", "string", "$", "order", ")", ":", "SortBy", "{", "$", "this", "->", "sortsBy", "[", "]", "=", "[", "'type'", "=>", "self", "::", "TYPE_FUNCTION", ",", "'function'", "=>", "$", "function", ",", "'order'", "=>", "$", "order", ",", "]", ";", "return", "$", "this", ";", "}" ]
Sort by function. @param string $function @param string $order @return SortBy
[ "Sort", "by", "function", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L360-L371
apisearch-io/php-client
Query/SortBy.php
SortBy.isSortedByGeoDistance
public function isSortedByGeoDistance(): bool { foreach ($this->sortsBy as $sortBy) { if (self::TYPE_DISTANCE === $sortBy['type']) { return true; } } return false; }
php
public function isSortedByGeoDistance(): bool { foreach ($this->sortsBy as $sortBy) { if (self::TYPE_DISTANCE === $sortBy['type']) { return true; } } return false; }
[ "public", "function", "isSortedByGeoDistance", "(", ")", ":", "bool", "{", "foreach", "(", "$", "this", "->", "sortsBy", "as", "$", "sortBy", ")", "{", "if", "(", "self", "::", "TYPE_DISTANCE", "===", "$", "sortBy", "[", "'type'", "]", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Is sorted by geo distance. @return bool
[ "Is", "sorted", "by", "geo", "distance", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L378-L387
apisearch-io/php-client
Query/SortBy.php
SortBy.setCoordinate
public function setCoordinate(Coordinate $coordinate) { $this->sortsBy = array_map(function (array $sortBy) use ($coordinate) { if (self::TYPE_DISTANCE === $sortBy['type']) { $sortBy['coordinate'] = $coordinate; } return $sortBy; }, $this->sortsBy); return $this; }
php
public function setCoordinate(Coordinate $coordinate) { $this->sortsBy = array_map(function (array $sortBy) use ($coordinate) { if (self::TYPE_DISTANCE === $sortBy['type']) { $sortBy['coordinate'] = $coordinate; } return $sortBy; }, $this->sortsBy); return $this; }
[ "public", "function", "setCoordinate", "(", "Coordinate", "$", "coordinate", ")", "{", "$", "this", "->", "sortsBy", "=", "array_map", "(", "function", "(", "array", "$", "sortBy", ")", "use", "(", "$", "coordinate", ")", "{", "if", "(", "self", "::", "TYPE_DISTANCE", "===", "$", "sortBy", "[", "'type'", "]", ")", "{", "$", "sortBy", "[", "'coordinate'", "]", "=", "$", "coordinate", ";", "}", "return", "$", "sortBy", ";", "}", ",", "$", "this", "->", "sortsBy", ")", ";", "return", "$", "this", ";", "}" ]
Set coordinate. @param Coordinate $coordinate @return SortBy
[ "Set", "coordinate", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L396-L407
apisearch-io/php-client
Query/SortBy.php
SortBy.toArray
public function toArray(): array { return array_map(function (array $sortBy) { if ( isset($sortBy['filter']) && ($sortBy['filter'] instanceof Filter) ) { $sortBy['filter'] = $sortBy['filter']->toArray(); } if ( isset($sortBy['coordinate']) && $sortBy['coordinate'] instanceof Coordinate ) { $sortBy['coordinate'] = $sortBy['coordinate']->toArray(); } return $sortBy; }, $this->sortsBy); }
php
public function toArray(): array { return array_map(function (array $sortBy) { if ( isset($sortBy['filter']) && ($sortBy['filter'] instanceof Filter) ) { $sortBy['filter'] = $sortBy['filter']->toArray(); } if ( isset($sortBy['coordinate']) && $sortBy['coordinate'] instanceof Coordinate ) { $sortBy['coordinate'] = $sortBy['coordinate']->toArray(); } return $sortBy; }, $this->sortsBy); }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "array", "$", "sortBy", ")", "{", "if", "(", "isset", "(", "$", "sortBy", "[", "'filter'", "]", ")", "&&", "(", "$", "sortBy", "[", "'filter'", "]", "instanceof", "Filter", ")", ")", "{", "$", "sortBy", "[", "'filter'", "]", "=", "$", "sortBy", "[", "'filter'", "]", "->", "toArray", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "sortBy", "[", "'coordinate'", "]", ")", "&&", "$", "sortBy", "[", "'coordinate'", "]", "instanceof", "Coordinate", ")", "{", "$", "sortBy", "[", "'coordinate'", "]", "=", "$", "sortBy", "[", "'coordinate'", "]", "->", "toArray", "(", ")", ";", "}", "return", "$", "sortBy", ";", "}", ",", "$", "this", "->", "sortsBy", ")", ";", "}" ]
To array. @return array
[ "To", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L414-L433
apisearch-io/php-client
Query/SortBy.php
SortBy.createFromArray
public static function createFromArray(array $array) { $sortBy = self::create(); $sortBy->sortsBy = array_map(function (array $element) { if ( self::RANDOM !== $element && self::SCORE !== $element ) { $element['type'] = $element['type'] ?? SortBy::TYPE_FIELD; } if (isset($element['filter'])) { $element['filter'] = Filter::createFromArray($element['filter']); } if ( isset($element['coordinate']) && is_array($element['coordinate']) ) { $element['coordinate'] = Coordinate::createFromArray($element['coordinate']); } return $element; }, $array); return $sortBy; }
php
public static function createFromArray(array $array) { $sortBy = self::create(); $sortBy->sortsBy = array_map(function (array $element) { if ( self::RANDOM !== $element && self::SCORE !== $element ) { $element['type'] = $element['type'] ?? SortBy::TYPE_FIELD; } if (isset($element['filter'])) { $element['filter'] = Filter::createFromArray($element['filter']); } if ( isset($element['coordinate']) && is_array($element['coordinate']) ) { $element['coordinate'] = Coordinate::createFromArray($element['coordinate']); } return $element; }, $array); return $sortBy; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "array", ")", "{", "$", "sortBy", "=", "self", "::", "create", "(", ")", ";", "$", "sortBy", "->", "sortsBy", "=", "array_map", "(", "function", "(", "array", "$", "element", ")", "{", "if", "(", "self", "::", "RANDOM", "!==", "$", "element", "&&", "self", "::", "SCORE", "!==", "$", "element", ")", "{", "$", "element", "[", "'type'", "]", "=", "$", "element", "[", "'type'", "]", "??", "SortBy", "::", "TYPE_FIELD", ";", "}", "if", "(", "isset", "(", "$", "element", "[", "'filter'", "]", ")", ")", "{", "$", "element", "[", "'filter'", "]", "=", "Filter", "::", "createFromArray", "(", "$", "element", "[", "'filter'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "element", "[", "'coordinate'", "]", ")", "&&", "is_array", "(", "$", "element", "[", "'coordinate'", "]", ")", ")", "{", "$", "element", "[", "'coordinate'", "]", "=", "Coordinate", "::", "createFromArray", "(", "$", "element", "[", "'coordinate'", "]", ")", ";", "}", "return", "$", "element", ";", "}", ",", "$", "array", ")", ";", "return", "$", "sortBy", ";", "}" ]
Create from array. @param array $array @return self @throws InvalidFormatException
[ "Create", "from", "array", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L444-L470
apisearch-io/php-client
Query/SortBy.php
SortBy.hasRandomSort
public function hasRandomSort() { foreach ($this->sortsBy as $sortBy) { if (self::TYPE_RANDOM === $sortBy['type']) { return true; } } return false; }
php
public function hasRandomSort() { foreach ($this->sortsBy as $sortBy) { if (self::TYPE_RANDOM === $sortBy['type']) { return true; } } return false; }
[ "public", "function", "hasRandomSort", "(", ")", "{", "foreach", "(", "$", "this", "->", "sortsBy", "as", "$", "sortBy", ")", "{", "if", "(", "self", "::", "TYPE_RANDOM", "===", "$", "sortBy", "[", "'type'", "]", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Has random sort. @return bool
[ "Has", "random", "sort", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/SortBy.php#L477-L486
apisearch-io/php-client
Query/Filter.php
Filter.create
public static function create( string $field, array $values, int $applicationType, string $filterType, array $filterTerms = [] ): self { return new self( $field, $values, $applicationType, $filterType, $filterTerms ); }
php
public static function create( string $field, array $values, int $applicationType, string $filterType, array $filterTerms = [] ): self { return new self( $field, $values, $applicationType, $filterType, $filterTerms ); }
[ "public", "static", "function", "create", "(", "string", "$", "field", ",", "array", "$", "values", ",", "int", "$", "applicationType", ",", "string", "$", "filterType", ",", "array", "$", "filterTerms", "=", "[", "]", ")", ":", "self", "{", "return", "new", "self", "(", "$", "field", ",", "$", "values", ",", "$", "applicationType", ",", "$", "filterType", ",", "$", "filterTerms", ")", ";", "}" ]
Create filter. @param string $field @param array $values @param int $applicationType @param string $filterType @param array $filterTerms @return Filter
[ "Create", "filter", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Filter.php#L229-L243