repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
ruflin/Elastica
|
lib/Elastica/Exception/ElasticsearchException.php
|
ElasticsearchException._parseError
|
protected function _parseError(string $error)
{
$errors = \explode(']; nested: ', $error);
if (1 === \count($errors)) {
$this->_exception = $this->_extractException($errors[0]);
} else {
if (self::REMOTE_TRANSPORT_EXCEPTION === $this->_extractException($errors[0])) {
$this->_isRemote = true;
$this->_exception = $this->_extractException($errors[1]);
} else {
$this->_exception = $this->_extractException($errors[0]);
}
}
}
|
php
|
protected function _parseError(string $error)
{
$errors = \explode(']; nested: ', $error);
if (1 === \count($errors)) {
$this->_exception = $this->_extractException($errors[0]);
} else {
if (self::REMOTE_TRANSPORT_EXCEPTION === $this->_extractException($errors[0])) {
$this->_isRemote = true;
$this->_exception = $this->_extractException($errors[1]);
} else {
$this->_exception = $this->_extractException($errors[0]);
}
}
}
|
[
"protected",
"function",
"_parseError",
"(",
"string",
"$",
"error",
")",
"{",
"$",
"errors",
"=",
"\\",
"explode",
"(",
"']; nested: '",
",",
"$",
"error",
")",
";",
"if",
"(",
"1",
"===",
"\\",
"count",
"(",
"$",
"errors",
")",
")",
"{",
"$",
"this",
"->",
"_exception",
"=",
"$",
"this",
"->",
"_extractException",
"(",
"$",
"errors",
"[",
"0",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"self",
"::",
"REMOTE_TRANSPORT_EXCEPTION",
"===",
"$",
"this",
"->",
"_extractException",
"(",
"$",
"errors",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_isRemote",
"=",
"true",
";",
"$",
"this",
"->",
"_exception",
"=",
"$",
"this",
"->",
"_extractException",
"(",
"$",
"errors",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_exception",
"=",
"$",
"this",
"->",
"_extractException",
"(",
"$",
"errors",
"[",
"0",
"]",
")",
";",
"}",
"}",
"}"
] |
Parse error message from elasticsearch.
@param string $error Error message
|
[
"Parse",
"error",
"message",
"from",
"elasticsearch",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Exception/ElasticsearchException.php#L48-L62
|
train
|
ruflin/Elastica
|
lib/Elastica/IndexTemplate.php
|
IndexTemplate.request
|
public function request($method, $data = [])
{
$path = '_template/'.$this->getName();
return $this->getClient()->request($path, $method, $data);
}
|
php
|
public function request($method, $data = [])
{
$path = '_template/'.$this->getName();
return $this->getClient()->request($path, $method, $data);
}
|
[
"public",
"function",
"request",
"(",
"$",
"method",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"path",
"=",
"'_template/'",
".",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"request",
"(",
"$",
"path",
",",
"$",
"method",
",",
"$",
"data",
")",
";",
"}"
] |
Makes calls to the elasticsearch server based on this index template name.
@param string $method Rest method to use (GET, POST, DELETE, PUT)
@param array $data OPTIONAL Arguments as array
@return \Elastica\Response Response object
|
[
"Makes",
"calls",
"to",
"the",
"elasticsearch",
"server",
"based",
"on",
"this",
"index",
"template",
"name",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/IndexTemplate.php#L114-L119
|
train
|
ruflin/Elastica
|
lib/Elastica/Snapshot.php
|
Snapshot.registerRepository
|
public function registerRepository($name, $type, $settings = [])
{
$data = [
'type' => $type,
'settings' => $settings,
];
return $this->request($name, Request::PUT, $data);
}
|
php
|
public function registerRepository($name, $type, $settings = [])
{
$data = [
'type' => $type,
'settings' => $settings,
];
return $this->request($name, Request::PUT, $data);
}
|
[
"public",
"function",
"registerRepository",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"settings",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'settings'",
"=>",
"$",
"settings",
",",
"]",
";",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"name",
",",
"Request",
"::",
"PUT",
",",
"$",
"data",
")",
";",
"}"
] |
Register a snapshot repository.
@param string $name the name of the repository
@param string $type the repository type ("fs" for file system)
@param array $settings Additional repository settings. If type "fs" is used, the "location" setting must be provided.
@return Response
|
[
"Register",
"a",
"snapshot",
"repository",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Snapshot.php#L38-L46
|
train
|
ruflin/Elastica
|
lib/Elastica/Snapshot.php
|
Snapshot.getRepository
|
public function getRepository($name)
{
try {
$response = $this->request($name);
} catch (ResponseException $e) {
if (404 == $e->getResponse()->getStatus()) {
throw new NotFoundException("Repository '".$name."' does not exist.");
}
throw $e;
}
$data = $response->getData();
return $data[$name];
}
|
php
|
public function getRepository($name)
{
try {
$response = $this->request($name);
} catch (ResponseException $e) {
if (404 == $e->getResponse()->getStatus()) {
throw new NotFoundException("Repository '".$name."' does not exist.");
}
throw $e;
}
$data = $response->getData();
return $data[$name];
}
|
[
"public",
"function",
"getRepository",
"(",
"$",
"name",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"request",
"(",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"ResponseException",
"$",
"e",
")",
"{",
"if",
"(",
"404",
"==",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getStatus",
"(",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"Repository '\"",
".",
"$",
"name",
".",
"\"' does not exist.\"",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"$",
"data",
"=",
"$",
"response",
"->",
"getData",
"(",
")",
";",
"return",
"$",
"data",
"[",
"$",
"name",
"]",
";",
"}"
] |
Retrieve a repository record by name.
@param string $name the name of the desired repository
@throws Exception\ResponseException
@throws Exception\NotFoundException
@return array
|
[
"Retrieve",
"a",
"repository",
"record",
"by",
"name",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Snapshot.php#L58-L71
|
train
|
ruflin/Elastica
|
lib/Elastica/Snapshot.php
|
Snapshot.createSnapshot
|
public function createSnapshot($repository, $name, $options = [], $waitForCompletion = false)
{
return $this->request($repository.'/'.$name, Request::PUT, $options, ['wait_for_completion' => $waitForCompletion]);
}
|
php
|
public function createSnapshot($repository, $name, $options = [], $waitForCompletion = false)
{
return $this->request($repository.'/'.$name, Request::PUT, $options, ['wait_for_completion' => $waitForCompletion]);
}
|
[
"public",
"function",
"createSnapshot",
"(",
"$",
"repository",
",",
"$",
"name",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"waitForCompletion",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"repository",
".",
"'/'",
".",
"$",
"name",
",",
"Request",
"::",
"PUT",
",",
"$",
"options",
",",
"[",
"'wait_for_completion'",
"=>",
"$",
"waitForCompletion",
"]",
")",
";",
"}"
] |
Create a new snapshot.
@param string $repository the name of the repository in which this snapshot should be stored
@param string $name the name of this snapshot
@param array $options optional settings for this snapshot
@param bool $waitForCompletion if true, the request will not return until the snapshot operation is complete
@return Response
|
[
"Create",
"a",
"new",
"snapshot",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Snapshot.php#L93-L96
|
train
|
ruflin/Elastica
|
lib/Elastica/Snapshot.php
|
Snapshot.getSnapshot
|
public function getSnapshot($repository, $name)
{
try {
$response = $this->request($repository.'/'.$name);
} catch (ResponseException $e) {
if (404 == $e->getResponse()->getStatus()) {
throw new NotFoundException("Snapshot '".$name."' does not exist in repository '".$repository."'.");
}
throw $e;
}
$data = $response->getData();
return $data['snapshots'][0];
}
|
php
|
public function getSnapshot($repository, $name)
{
try {
$response = $this->request($repository.'/'.$name);
} catch (ResponseException $e) {
if (404 == $e->getResponse()->getStatus()) {
throw new NotFoundException("Snapshot '".$name."' does not exist in repository '".$repository."'.");
}
throw $e;
}
$data = $response->getData();
return $data['snapshots'][0];
}
|
[
"public",
"function",
"getSnapshot",
"(",
"$",
"repository",
",",
"$",
"name",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"request",
"(",
"$",
"repository",
".",
"'/'",
".",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"ResponseException",
"$",
"e",
")",
"{",
"if",
"(",
"404",
"==",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getStatus",
"(",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"\"Snapshot '\"",
".",
"$",
"name",
".",
"\"' does not exist in repository '\"",
".",
"$",
"repository",
".",
"\"'.\"",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"$",
"data",
"=",
"$",
"response",
"->",
"getData",
"(",
")",
";",
"return",
"$",
"data",
"[",
"'snapshots'",
"]",
"[",
"0",
"]",
";",
"}"
] |
Retrieve data regarding a specific snapshot.
@param string $repository the name of the repository from which to retrieve the snapshot
@param string $name the name of the desired snapshot
@throws Exception\ResponseException
@throws Exception\NotFoundException
@return array
|
[
"Retrieve",
"data",
"regarding",
"a",
"specific",
"snapshot",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Snapshot.php#L109-L122
|
train
|
ruflin/Elastica
|
lib/Elastica/Snapshot.php
|
Snapshot.restoreSnapshot
|
public function restoreSnapshot($repository, $name, $options = [], $waitForCompletion = false)
{
$endpoint = new Restore();
$endpoint->setRepository($repository);
$endpoint->setSnapshot($name);
$endpoint->setBody($options);
$endpoint->setParams(['wait_for_completion' => $waitForCompletion]);
return $this->_client->requestEndpoint($endpoint);
}
|
php
|
public function restoreSnapshot($repository, $name, $options = [], $waitForCompletion = false)
{
$endpoint = new Restore();
$endpoint->setRepository($repository);
$endpoint->setSnapshot($name);
$endpoint->setBody($options);
$endpoint->setParams(['wait_for_completion' => $waitForCompletion]);
return $this->_client->requestEndpoint($endpoint);
}
|
[
"public",
"function",
"restoreSnapshot",
"(",
"$",
"repository",
",",
"$",
"name",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"waitForCompletion",
"=",
"false",
")",
"{",
"$",
"endpoint",
"=",
"new",
"Restore",
"(",
")",
";",
"$",
"endpoint",
"->",
"setRepository",
"(",
"$",
"repository",
")",
";",
"$",
"endpoint",
"->",
"setSnapshot",
"(",
"$",
"name",
")",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"options",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"[",
"'wait_for_completion'",
"=>",
"$",
"waitForCompletion",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_client",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] |
Restore a snapshot.
@param string $repository the name of the repository
@param string $name the name of the snapshot
@param array $options options for the restore operation
@param bool $waitForCompletion if true, the request will not return until the restore operation is complete
@return Response
|
[
"Restore",
"a",
"snapshot",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Snapshot.php#L159-L168
|
train
|
ruflin/Elastica
|
lib/Elastica/Snapshot.php
|
Snapshot.request
|
public function request($path, $method = Request::GET, $data = [], array $query = [])
{
return $this->_client->request('_snapshot/'.$path, $method, $data, $query);
}
|
php
|
public function request($path, $method = Request::GET, $data = [], array $query = [])
{
return $this->_client->request('_snapshot/'.$path, $method, $data, $query);
}
|
[
"public",
"function",
"request",
"(",
"$",
"path",
",",
"$",
"method",
"=",
"Request",
"::",
"GET",
",",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"query",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"_client",
"->",
"request",
"(",
"'_snapshot/'",
".",
"$",
"path",
",",
"$",
"method",
",",
"$",
"data",
",",
"$",
"query",
")",
";",
"}"
] |
Perform a snapshot request.
@param string $path the URL
@param string $method the HTTP method
@param array $data request body data
@param array $query query string parameters
@return Response
|
[
"Perform",
"a",
"snapshot",
"request",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Snapshot.php#L180-L183
|
train
|
ruflin/Elastica
|
lib/Elastica/Cluster/Settings.php
|
Settings.getPersistent
|
public function getPersistent(string $setting = '')
{
$data = $this->get();
$settings = $data['persistent'];
if ('' !== $setting) {
return $settings[$setting] ?? null;
}
return $settings;
}
|
php
|
public function getPersistent(string $setting = '')
{
$data = $this->get();
$settings = $data['persistent'];
if ('' !== $setting) {
return $settings[$setting] ?? null;
}
return $settings;
}
|
[
"public",
"function",
"getPersistent",
"(",
"string",
"$",
"setting",
"=",
"''",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"get",
"(",
")",
";",
"$",
"settings",
"=",
"$",
"data",
"[",
"'persistent'",
"]",
";",
"if",
"(",
"''",
"!==",
"$",
"setting",
")",
"{",
"return",
"$",
"settings",
"[",
"$",
"setting",
"]",
"??",
"null",
";",
"}",
"return",
"$",
"settings",
";",
"}"
] |
Returns the current persistent settings of the cluster.
If param is set, only specified setting is return.
@param string $setting OPTIONAL Setting name to return
@return array|string|null Settings data
|
[
"Returns",
"the",
"current",
"persistent",
"settings",
"of",
"the",
"cluster",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Cluster/Settings.php#L52-L62
|
train
|
ruflin/Elastica
|
lib/Elastica/Cluster/Settings.php
|
Settings.getTransient
|
public function getTransient(string $setting = '')
{
$data = $this->get();
$settings = $data['transient'];
if ('' !== $setting) {
if (isset($settings[$setting])) {
return $settings[$setting];
}
if (false !== \strpos($setting, '.')) {
// convert dot notation to nested arrays
$keys = \explode('.', $setting);
foreach ($keys as $key) {
if (isset($settings[$key])) {
$settings = $settings[$key];
} else {
return null;
}
}
return $settings;
}
return null;
}
return $settings;
}
|
php
|
public function getTransient(string $setting = '')
{
$data = $this->get();
$settings = $data['transient'];
if ('' !== $setting) {
if (isset($settings[$setting])) {
return $settings[$setting];
}
if (false !== \strpos($setting, '.')) {
// convert dot notation to nested arrays
$keys = \explode('.', $setting);
foreach ($keys as $key) {
if (isset($settings[$key])) {
$settings = $settings[$key];
} else {
return null;
}
}
return $settings;
}
return null;
}
return $settings;
}
|
[
"public",
"function",
"getTransient",
"(",
"string",
"$",
"setting",
"=",
"''",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"get",
"(",
")",
";",
"$",
"settings",
"=",
"$",
"data",
"[",
"'transient'",
"]",
";",
"if",
"(",
"''",
"!==",
"$",
"setting",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"settings",
"[",
"$",
"setting",
"]",
")",
")",
"{",
"return",
"$",
"settings",
"[",
"$",
"setting",
"]",
";",
"}",
"if",
"(",
"false",
"!==",
"\\",
"strpos",
"(",
"$",
"setting",
",",
"'.'",
")",
")",
"{",
"// convert dot notation to nested arrays",
"$",
"keys",
"=",
"\\",
"explode",
"(",
"'.'",
",",
"$",
"setting",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"settings",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"settings",
"=",
"$",
"settings",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"settings",
";",
"}",
"return",
"null",
";",
"}",
"return",
"$",
"settings",
";",
"}"
] |
Returns the current transient settings of the cluster.
If param is set, only specified setting is return.
@param string $setting OPTIONAL Setting name to return
@return array|string|null Settings data
|
[
"Returns",
"the",
"current",
"transient",
"settings",
"of",
"the",
"cluster",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Cluster/Settings.php#L73-L101
|
train
|
ruflin/Elastica
|
lib/Elastica/Cluster/Settings.php
|
Settings.setReadOnly
|
public function setReadOnly(bool $readOnly = true, bool $persistent = false): Response
{
$key = 'cluster.blocks.read_only';
if ($persistent) {
return $this->setPersistent($key, $readOnly);
}
return $this->setTransient($key, $readOnly);
}
|
php
|
public function setReadOnly(bool $readOnly = true, bool $persistent = false): Response
{
$key = 'cluster.blocks.read_only';
if ($persistent) {
return $this->setPersistent($key, $readOnly);
}
return $this->setTransient($key, $readOnly);
}
|
[
"public",
"function",
"setReadOnly",
"(",
"bool",
"$",
"readOnly",
"=",
"true",
",",
"bool",
"$",
"persistent",
"=",
"false",
")",
":",
"Response",
"{",
"$",
"key",
"=",
"'cluster.blocks.read_only'",
";",
"if",
"(",
"$",
"persistent",
")",
"{",
"return",
"$",
"this",
"->",
"setPersistent",
"(",
"$",
"key",
",",
"$",
"readOnly",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setTransient",
"(",
"$",
"key",
",",
"$",
"readOnly",
")",
";",
"}"
] |
Sets the cluster to read only.
Second param can be used to set it persistent
@param bool $readOnly
@param bool $persistent
@return Response $response
|
[
"Sets",
"the",
"cluster",
"to",
"read",
"only",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Cluster/Settings.php#L151-L160
|
train
|
ruflin/Elastica
|
lib/Elastica/Cluster/Settings.php
|
Settings.request
|
public function request(array $data = [], string $method = Request::GET): Response
{
$path = '_cluster/settings';
return $this->getClient()->request($path, $method, $data);
}
|
php
|
public function request(array $data = [], string $method = Request::GET): Response
{
$path = '_cluster/settings';
return $this->getClient()->request($path, $method, $data);
}
|
[
"public",
"function",
"request",
"(",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"string",
"$",
"method",
"=",
"Request",
"::",
"GET",
")",
":",
"Response",
"{",
"$",
"path",
"=",
"'_cluster/settings'",
";",
"return",
"$",
"this",
"->",
"getClient",
"(",
")",
"->",
"request",
"(",
"$",
"path",
",",
"$",
"method",
",",
"$",
"data",
")",
";",
"}"
] |
Sends settings request.
@param array $data OPTIONAL Data array
@param string $method OPTIONAL Transfer method (default = \Elastica\Request::GET)
@return Response Response object
|
[
"Sends",
"settings",
"request",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Cluster/Settings.php#L192-L197
|
train
|
ruflin/Elastica
|
lib/Elastica/Cluster.php
|
Cluster.getNodeNames
|
public function getNodeNames()
{
$data = $this->getState();
$nodeNames = [];
foreach ($data['nodes'] as $node) {
$nodeNames[] = $node['name'];
}
return $nodeNames;
}
|
php
|
public function getNodeNames()
{
$data = $this->getState();
$nodeNames = [];
foreach ($data['nodes'] as $node) {
$nodeNames[] = $node['name'];
}
return $nodeNames;
}
|
[
"public",
"function",
"getNodeNames",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"nodeNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"'nodes'",
"]",
"as",
"$",
"node",
")",
"{",
"$",
"nodeNames",
"[",
"]",
"=",
"$",
"node",
"[",
"'name'",
"]",
";",
"}",
"return",
"$",
"nodeNames",
";",
"}"
] |
Returns a list of existing node names.
@return array List of node names
|
[
"Returns",
"a",
"list",
"of",
"existing",
"node",
"names",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Cluster.php#L97-L106
|
train
|
ruflin/Elastica
|
lib/Elastica/Cluster.php
|
Cluster.getNodes
|
public function getNodes()
{
$nodes = [];
$data = $this->getState();
foreach ($data['nodes'] as $id => $name) {
$nodes[] = new Node($id, $this->getClient());
}
return $nodes;
}
|
php
|
public function getNodes()
{
$nodes = [];
$data = $this->getState();
foreach ($data['nodes'] as $id => $name) {
$nodes[] = new Node($id, $this->getClient());
}
return $nodes;
}
|
[
"public",
"function",
"getNodes",
"(",
")",
"{",
"$",
"nodes",
"=",
"[",
"]",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"[",
"'nodes'",
"]",
"as",
"$",
"id",
"=>",
"$",
"name",
")",
"{",
"$",
"nodes",
"[",
"]",
"=",
"new",
"Node",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"getClient",
"(",
")",
")",
";",
"}",
"return",
"$",
"nodes",
";",
"}"
] |
Returns all nodes of the cluster.
@return \Elastica\Node[]
|
[
"Returns",
"all",
"nodes",
"of",
"the",
"cluster",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Cluster.php#L113-L123
|
train
|
ruflin/Elastica
|
lib/Elastica/Request.php
|
Request.send
|
public function send()
{
$transport = $this->getConnection()->getTransportObject();
// Refactor: Not full toArray needed in exec?
return $transport->exec($this, $this->getConnection()->toArray());
}
|
php
|
public function send()
{
$transport = $this->getConnection()->getTransportObject();
// Refactor: Not full toArray needed in exec?
return $transport->exec($this, $this->getConnection()->toArray());
}
|
[
"public",
"function",
"send",
"(",
")",
"{",
"$",
"transport",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"getTransportObject",
"(",
")",
";",
"// Refactor: Not full toArray needed in exec?",
"return",
"$",
"transport",
"->",
"exec",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"toArray",
"(",
")",
")",
";",
"}"
] |
Sends request to server.
@return \Elastica\Response Response object
|
[
"Sends",
"request",
"to",
"server",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Request.php#L189-L195
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/InnerHits.php
|
InnerHits.addScriptField
|
public function addScriptField(string $name, AbstractScript $script): self
{
if (!isset($this->_params['script_fields'])) {
$this->_params['script_fields'] = new ScriptFields();
}
$this->_params['script_fields']->addScript($name, $script);
return $this;
}
|
php
|
public function addScriptField(string $name, AbstractScript $script): self
{
if (!isset($this->_params['script_fields'])) {
$this->_params['script_fields'] = new ScriptFields();
}
$this->_params['script_fields']->addScript($name, $script);
return $this;
}
|
[
"public",
"function",
"addScriptField",
"(",
"string",
"$",
"name",
",",
"AbstractScript",
"$",
"script",
")",
":",
"self",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_params",
"[",
"'script_fields'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_params",
"[",
"'script_fields'",
"]",
"=",
"new",
"ScriptFields",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_params",
"[",
"'script_fields'",
"]",
"->",
"addScript",
"(",
"$",
"name",
",",
"$",
"script",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a Script to the aggregation.
@param string $name
@param AbstractScript $script
@return $this
|
[
"Adds",
"a",
"Script",
"to",
"the",
"aggregation",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/InnerHits.php#L138-L147
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client.getVersion
|
public function getVersion()
{
if ($this->_version) {
return $this->_version;
}
$data = $this->request('/')->getData();
return $this->_version = $data['version']['number'];
}
|
php
|
public function getVersion()
{
if ($this->_version) {
return $this->_version;
}
$data = $this->request('/')->getData();
return $this->_version = $data['version']['number'];
}
|
[
"public",
"function",
"getVersion",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_version",
")",
"{",
"return",
"$",
"this",
"->",
"_version",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"request",
"(",
"'/'",
")",
"->",
"getData",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_version",
"=",
"$",
"data",
"[",
"'version'",
"]",
"[",
"'number'",
"]",
";",
"}"
] |
Get current version.
@return string
|
[
"Get",
"current",
"version",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L105-L114
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client._initConnections
|
protected function _initConnections()
{
$connections = [];
foreach ($this->getConfig('connections') as $connection) {
$connections[] = Connection::create($this->_prepareConnectionParams($connection));
}
if (isset($this->_config['servers'])) {
foreach ($this->getConfig('servers') as $server) {
$connections[] = Connection::create($this->_prepareConnectionParams($server));
}
}
// If no connections set, create default connection
if (empty($connections)) {
$connections[] = Connection::create($this->_prepareConnectionParams($this->getConfig()));
}
if (!isset($this->_config['connectionStrategy'])) {
if (true === $this->getConfig('roundRobin')) {
$this->setConfigValue('connectionStrategy', 'RoundRobin');
} else {
$this->setConfigValue('connectionStrategy', 'Simple');
}
}
$strategy = Connection\Strategy\StrategyFactory::create($this->getConfig('connectionStrategy'));
$this->_connectionPool = new Connection\ConnectionPool($connections, $strategy, $this->_callback);
}
|
php
|
protected function _initConnections()
{
$connections = [];
foreach ($this->getConfig('connections') as $connection) {
$connections[] = Connection::create($this->_prepareConnectionParams($connection));
}
if (isset($this->_config['servers'])) {
foreach ($this->getConfig('servers') as $server) {
$connections[] = Connection::create($this->_prepareConnectionParams($server));
}
}
// If no connections set, create default connection
if (empty($connections)) {
$connections[] = Connection::create($this->_prepareConnectionParams($this->getConfig()));
}
if (!isset($this->_config['connectionStrategy'])) {
if (true === $this->getConfig('roundRobin')) {
$this->setConfigValue('connectionStrategy', 'RoundRobin');
} else {
$this->setConfigValue('connectionStrategy', 'Simple');
}
}
$strategy = Connection\Strategy\StrategyFactory::create($this->getConfig('connectionStrategy'));
$this->_connectionPool = new Connection\ConnectionPool($connections, $strategy, $this->_callback);
}
|
[
"protected",
"function",
"_initConnections",
"(",
")",
"{",
"$",
"connections",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'connections'",
")",
"as",
"$",
"connection",
")",
"{",
"$",
"connections",
"[",
"]",
"=",
"Connection",
"::",
"create",
"(",
"$",
"this",
"->",
"_prepareConnectionParams",
"(",
"$",
"connection",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_config",
"[",
"'servers'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'servers'",
")",
"as",
"$",
"server",
")",
"{",
"$",
"connections",
"[",
"]",
"=",
"Connection",
"::",
"create",
"(",
"$",
"this",
"->",
"_prepareConnectionParams",
"(",
"$",
"server",
")",
")",
";",
"}",
"}",
"// If no connections set, create default connection",
"if",
"(",
"empty",
"(",
"$",
"connections",
")",
")",
"{",
"$",
"connections",
"[",
"]",
"=",
"Connection",
"::",
"create",
"(",
"$",
"this",
"->",
"_prepareConnectionParams",
"(",
"$",
"this",
"->",
"getConfig",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_config",
"[",
"'connectionStrategy'",
"]",
")",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"getConfig",
"(",
"'roundRobin'",
")",
")",
"{",
"$",
"this",
"->",
"setConfigValue",
"(",
"'connectionStrategy'",
",",
"'RoundRobin'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setConfigValue",
"(",
"'connectionStrategy'",
",",
"'Simple'",
")",
";",
"}",
"}",
"$",
"strategy",
"=",
"Connection",
"\\",
"Strategy",
"\\",
"StrategyFactory",
"::",
"create",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'connectionStrategy'",
")",
")",
";",
"$",
"this",
"->",
"_connectionPool",
"=",
"new",
"Connection",
"\\",
"ConnectionPool",
"(",
"$",
"connections",
",",
"$",
"strategy",
",",
"$",
"this",
"->",
"_callback",
")",
";",
"}"
] |
Inits the client connections.
|
[
"Inits",
"the",
"client",
"connections",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L119-L149
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client._prepareConnectionParams
|
protected function _prepareConnectionParams(array $config)
{
$params = [];
$params['config'] = [];
foreach ($config as $key => $value) {
if (\in_array($key, ['bigintConversion', 'curl', 'headers', 'url'])) {
$params['config'][$key] = $value;
} else {
$params[$key] = $value;
}
}
return $params;
}
|
php
|
protected function _prepareConnectionParams(array $config)
{
$params = [];
$params['config'] = [];
foreach ($config as $key => $value) {
if (\in_array($key, ['bigintConversion', 'curl', 'headers', 'url'])) {
$params['config'][$key] = $value;
} else {
$params[$key] = $value;
}
}
return $params;
}
|
[
"protected",
"function",
"_prepareConnectionParams",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"$",
"params",
"[",
"'config'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"key",
",",
"[",
"'bigintConversion'",
",",
"'curl'",
",",
"'headers'",
",",
"'url'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'config'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"params",
";",
"}"
] |
Creates a Connection params array from a Client or server config array.
@param array $config
@return array
|
[
"Creates",
"a",
"Connection",
"params",
"array",
"from",
"a",
"Client",
"or",
"server",
"config",
"array",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L158-L171
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client.addHeader
|
public function addHeader($header, $headerValue)
{
if (\is_string($header) && \is_string($headerValue)) {
$this->_config['headers'][$header] = $headerValue;
} else {
throw new InvalidException('Header must be a string');
}
return $this;
}
|
php
|
public function addHeader($header, $headerValue)
{
if (\is_string($header) && \is_string($headerValue)) {
$this->_config['headers'][$header] = $headerValue;
} else {
throw new InvalidException('Header must be a string');
}
return $this;
}
|
[
"public",
"function",
"addHeader",
"(",
"$",
"header",
",",
"$",
"headerValue",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"header",
")",
"&&",
"\\",
"is_string",
"(",
"$",
"headerValue",
")",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'headers'",
"]",
"[",
"$",
"header",
"]",
"=",
"$",
"headerValue",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Header must be a string'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Adds a HTTP Header.
@param string $header The HTTP Header
@param string $headerValue The HTTP Header Value
@throws \Elastica\Exception\InvalidException If $header or $headerValue is not a string
@return $this
|
[
"Adds",
"a",
"HTTP",
"Header",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L267-L276
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client.removeHeader
|
public function removeHeader($header)
{
if (\is_string($header)) {
if (\array_key_exists($header, $this->_config['headers'])) {
unset($this->_config['headers'][$header]);
}
} else {
throw new InvalidException('Header must be a string');
}
return $this;
}
|
php
|
public function removeHeader($header)
{
if (\is_string($header)) {
if (\array_key_exists($header, $this->_config['headers'])) {
unset($this->_config['headers'][$header]);
}
} else {
throw new InvalidException('Header must be a string');
}
return $this;
}
|
[
"public",
"function",
"removeHeader",
"(",
"$",
"header",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"header",
")",
")",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"header",
",",
"$",
"this",
"->",
"_config",
"[",
"'headers'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_config",
"[",
"'headers'",
"]",
"[",
"$",
"header",
"]",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Header must be a string'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Remove a HTTP Header.
@param string $header The HTTP Header to remove
@throws \Elastica\Exception\InvalidException If $header is not a string
@return $this
|
[
"Remove",
"a",
"HTTP",
"Header",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L287-L298
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client.deleteIds
|
public function deleteIds(array $ids, $index, $type, $routing = false)
{
if (empty($ids)) {
throw new InvalidException('Array has to consist of at least one id');
}
$bulk = new Bulk($this);
$bulk->setIndex($index);
$bulk->setType($type);
foreach ($ids as $id) {
$action = new Action(Action::OP_TYPE_DELETE);
$action->setId($id);
if (!empty($routing)) {
$action->setRouting($routing);
}
$bulk->addAction($action);
}
return $bulk->send();
}
|
php
|
public function deleteIds(array $ids, $index, $type, $routing = false)
{
if (empty($ids)) {
throw new InvalidException('Array has to consist of at least one id');
}
$bulk = new Bulk($this);
$bulk->setIndex($index);
$bulk->setType($type);
foreach ($ids as $id) {
$action = new Action(Action::OP_TYPE_DELETE);
$action->setId($id);
if (!empty($routing)) {
$action->setRouting($routing);
}
$bulk->addAction($action);
}
return $bulk->send();
}
|
[
"public",
"function",
"deleteIds",
"(",
"array",
"$",
"ids",
",",
"$",
"index",
",",
"$",
"type",
",",
"$",
"routing",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Array has to consist of at least one id'",
")",
";",
"}",
"$",
"bulk",
"=",
"new",
"Bulk",
"(",
"$",
"this",
")",
";",
"$",
"bulk",
"->",
"setIndex",
"(",
"$",
"index",
")",
";",
"$",
"bulk",
"->",
"setType",
"(",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"$",
"action",
"=",
"new",
"Action",
"(",
"Action",
"::",
"OP_TYPE_DELETE",
")",
";",
"$",
"action",
"->",
"setId",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"routing",
")",
")",
"{",
"$",
"action",
"->",
"setRouting",
"(",
"$",
"routing",
")",
";",
"}",
"$",
"bulk",
"->",
"addAction",
"(",
"$",
"action",
")",
";",
"}",
"return",
"$",
"bulk",
"->",
"send",
"(",
")",
";",
"}"
] |
Deletes documents with the given ids, index, type from the index.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
@param array $ids Document ids
@param string|\Elastica\Index $index Index name
@param string|\Elastica\Type $type Type of documents
@param string|bool $routing Optional routing key for all ids
@throws \Elastica\Exception\InvalidException
@return \Elastica\Bulk\ResponseSet Response object
|
[
"Deletes",
"documents",
"with",
"the",
"given",
"ids",
"index",
"type",
"from",
"the",
"index",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L609-L631
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client.bulk
|
public function bulk(array $params)
{
if (empty($params)) {
throw new InvalidException('Array has to consist of at least one param');
}
$bulk = new Bulk($this);
$bulk->addRawData($params);
return $bulk->send();
}
|
php
|
public function bulk(array $params)
{
if (empty($params)) {
throw new InvalidException('Array has to consist of at least one param');
}
$bulk = new Bulk($this);
$bulk->addRawData($params);
return $bulk->send();
}
|
[
"public",
"function",
"bulk",
"(",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Array has to consist of at least one param'",
")",
";",
"}",
"$",
"bulk",
"=",
"new",
"Bulk",
"(",
"$",
"this",
")",
";",
"$",
"bulk",
"->",
"addRawData",
"(",
"$",
"params",
")",
";",
"return",
"$",
"bulk",
"->",
"send",
"(",
")",
";",
"}"
] |
Bulk operation.
Every entry in the params array has to exactly on array
of the bulk operation. An example param array would be:
array(
array('index' => array('_index' => 'test', '_type' => 'user', '_id' => '1')),
array('user' => array('name' => 'hans')),
array('delete' => array('_index' => 'test', '_type' => 'user', '_id' => '2'))
);
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
@param array $params Parameter array
@throws \Elastica\Exception\ResponseException
@throws \Elastica\Exception\InvalidException
@return \Elastica\Bulk\ResponseSet Response object
|
[
"Bulk",
"operation",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L654-L665
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client.request
|
public function request($path, $method = Request::GET, $data = [], array $query = [], $contentType = Request::DEFAULT_CONTENT_TYPE)
{
$connection = $this->getConnection();
$request = $this->_lastRequest = new Request($path, $method, $data, $query, $connection, $contentType);
$this->_lastResponse = null;
try {
$response = $this->_lastResponse = $request->send();
} catch (ConnectionException $e) {
$this->_connectionPool->onFail($connection, $e, $this);
$this->_log($e);
// In case there is no valid connection left, throw exception which caused the disabling of the connection.
if (!$this->hasConnection()) {
throw $e;
}
return $this->request($path, $method, $data, $query);
}
$this->_log($request);
return $response;
}
|
php
|
public function request($path, $method = Request::GET, $data = [], array $query = [], $contentType = Request::DEFAULT_CONTENT_TYPE)
{
$connection = $this->getConnection();
$request = $this->_lastRequest = new Request($path, $method, $data, $query, $connection, $contentType);
$this->_lastResponse = null;
try {
$response = $this->_lastResponse = $request->send();
} catch (ConnectionException $e) {
$this->_connectionPool->onFail($connection, $e, $this);
$this->_log($e);
// In case there is no valid connection left, throw exception which caused the disabling of the connection.
if (!$this->hasConnection()) {
throw $e;
}
return $this->request($path, $method, $data, $query);
}
$this->_log($request);
return $response;
}
|
[
"public",
"function",
"request",
"(",
"$",
"path",
",",
"$",
"method",
"=",
"Request",
"::",
"GET",
",",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"query",
"=",
"[",
"]",
",",
"$",
"contentType",
"=",
"Request",
"::",
"DEFAULT_CONTENT_TYPE",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"_lastRequest",
"=",
"new",
"Request",
"(",
"$",
"path",
",",
"$",
"method",
",",
"$",
"data",
",",
"$",
"query",
",",
"$",
"connection",
",",
"$",
"contentType",
")",
";",
"$",
"this",
"->",
"_lastResponse",
"=",
"null",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_lastResponse",
"=",
"$",
"request",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"ConnectionException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"_connectionPool",
"->",
"onFail",
"(",
"$",
"connection",
",",
"$",
"e",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_log",
"(",
"$",
"e",
")",
";",
"// In case there is no valid connection left, throw exception which caused the disabling of the connection.",
"if",
"(",
"!",
"$",
"this",
"->",
"hasConnection",
"(",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"path",
",",
"$",
"method",
",",
"$",
"data",
",",
"$",
"query",
")",
";",
"}",
"$",
"this",
"->",
"_log",
"(",
"$",
"request",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Makes calls to the elasticsearch server based on this index.
It's possible to make any REST query directly over this method
@param string $path Path to call
@param string $method Rest method to use (GET, POST, DELETE, PUT)
@param array|string $data OPTIONAL Arguments as array or pre-encoded string
@param array $query OPTIONAL Query params
@param string $contentType Content-Type sent with this request
@throws Exception\ConnectionException|Exception\ClientException
@return Response Response object
|
[
"Makes",
"calls",
"to",
"the",
"elasticsearch",
"server",
"based",
"on",
"this",
"index",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L682-L706
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client.requestEndpoint
|
public function requestEndpoint(AbstractEndpoint $endpoint)
{
return $this->request(
\ltrim($endpoint->getURI(), '/'),
$endpoint->getMethod(),
null === $endpoint->getBody() ? [] : $endpoint->getBody(),
$endpoint->getParams()
);
}
|
php
|
public function requestEndpoint(AbstractEndpoint $endpoint)
{
return $this->request(
\ltrim($endpoint->getURI(), '/'),
$endpoint->getMethod(),
null === $endpoint->getBody() ? [] : $endpoint->getBody(),
$endpoint->getParams()
);
}
|
[
"public",
"function",
"requestEndpoint",
"(",
"AbstractEndpoint",
"$",
"endpoint",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"(",
"\\",
"ltrim",
"(",
"$",
"endpoint",
"->",
"getURI",
"(",
")",
",",
"'/'",
")",
",",
"$",
"endpoint",
"->",
"getMethod",
"(",
")",
",",
"null",
"===",
"$",
"endpoint",
"->",
"getBody",
"(",
")",
"?",
"[",
"]",
":",
"$",
"endpoint",
"->",
"getBody",
"(",
")",
",",
"$",
"endpoint",
"->",
"getParams",
"(",
")",
")",
";",
"}"
] |
Makes calls to the elasticsearch server with usage official client Endpoint.
@param AbstractEndpoint $endpoint
@return Response
|
[
"Makes",
"calls",
"to",
"the",
"elasticsearch",
"server",
"with",
"usage",
"official",
"client",
"Endpoint",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L715-L723
|
train
|
ruflin/Elastica
|
lib/Elastica/Client.php
|
Client.forcemergeAll
|
public function forcemergeAll($args = [])
{
$endpoint = new ForceMerge();
$endpoint->setParams($args);
return $this->requestEndpoint($endpoint);
}
|
php
|
public function forcemergeAll($args = [])
{
$endpoint = new ForceMerge();
$endpoint->setParams($args);
return $this->requestEndpoint($endpoint);
}
|
[
"public",
"function",
"forcemergeAll",
"(",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"endpoint",
"=",
"new",
"ForceMerge",
"(",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] |
Force merges all search indices.
@param array $args OPTIONAL Optional arguments
@return \Elastica\Response Response object
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html
|
[
"Force",
"merges",
"all",
"search",
"indices",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Client.php#L785-L791
|
train
|
ruflin/Elastica
|
lib/Elastica/AbstractUpdateAction.php
|
AbstractUpdateAction.setType
|
public function setType($type)
{
if ($type instanceof Type) {
$this->setIndex($type->getIndex());
$type = $type->getName();
}
return $this->setParam('_type', $type);
}
|
php
|
public function setType($type)
{
if ($type instanceof Type) {
$this->setIndex($type->getIndex());
$type = $type->getName();
}
return $this->setParam('_type', $type);
}
|
[
"public",
"function",
"setType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"instanceof",
"Type",
")",
"{",
"$",
"this",
"->",
"setIndex",
"(",
"$",
"type",
"->",
"getIndex",
"(",
")",
")",
";",
"$",
"type",
"=",
"$",
"type",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'_type'",
",",
"$",
"type",
")",
";",
"}"
] |
Sets the document type name.
@param Type|string $type Type name
@return $this
|
[
"Sets",
"the",
"document",
"type",
"name",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/AbstractUpdateAction.php#L55-L63
|
train
|
ruflin/Elastica
|
lib/Elastica/AbstractUpdateAction.php
|
AbstractUpdateAction.setIndex
|
public function setIndex($index)
{
if ($index instanceof Index) {
$index = $index->getName();
}
return $this->setParam('_index', $index);
}
|
php
|
public function setIndex($index)
{
if ($index instanceof Index) {
$index = $index->getName();
}
return $this->setParam('_index', $index);
}
|
[
"public",
"function",
"setIndex",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"index",
"instanceof",
"Index",
")",
"{",
"$",
"index",
"=",
"$",
"index",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'_index'",
",",
"$",
"index",
")",
";",
"}"
] |
Sets the document index name.
@param Index|string $index Index name
@return $this
|
[
"Sets",
"the",
"document",
"index",
"name",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/AbstractUpdateAction.php#L84-L91
|
train
|
ruflin/Elastica
|
lib/Elastica/Transport/AbstractTransport.php
|
AbstractTransport.sanityzeQueryStringBool
|
public function sanityzeQueryStringBool(array $query)
{
foreach ($query as $key => $value) {
if (\is_bool($value)) {
$query[$key] = ($value) ? 'true' : 'false';
}
}
return $query;
}
|
php
|
public function sanityzeQueryStringBool(array $query)
{
foreach ($query as $key => $value) {
if (\is_bool($value)) {
$query[$key] = ($value) ? 'true' : 'false';
}
}
return $query;
}
|
[
"public",
"function",
"sanityzeQueryStringBool",
"(",
"array",
"$",
"query",
")",
"{",
"foreach",
"(",
"$",
"query",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"\\",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"query",
"[",
"$",
"key",
"]",
"=",
"(",
"$",
"value",
")",
"?",
"'true'",
":",
"'false'",
";",
"}",
"}",
"return",
"$",
"query",
";",
"}"
] |
BOOL values true|false should be sanityzed and passed to Elasticsearch
as string.
@param array $query
@return mixed
|
[
"BOOL",
"values",
"true|false",
"should",
"be",
"sanityzed",
"and",
"passed",
"to",
"Elasticsearch",
"as",
"string",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Transport/AbstractTransport.php#L73-L82
|
train
|
ruflin/Elastica
|
lib/Elastica/Transport/AbstractTransport.php
|
AbstractTransport.create
|
public static function create($transport, Connection $connection, array $params = []): AbstractTransport
{
if (\is_array($transport) && isset($transport['type'])) {
$transportParams = $transport;
unset($transportParams['type']);
$params = \array_replace($params, $transportParams);
$transport = $transport['type'];
}
if (\is_string($transport)) {
$specialTransports = [
'httpadapter' => 'HttpAdapter',
'nulltransport' => 'NullTransport',
];
if (isset($specialTransports[\strtolower($transport)])) {
$transport = $specialTransports[\strtolower($transport)];
} else {
$transport = \ucfirst($transport);
}
$classNames = ["Elastica\\Transport\\$transport", $transport];
foreach ($classNames as $className) {
if (\class_exists($className)) {
$transport = new $className();
break;
}
}
}
if ($transport instanceof self) {
$transport->setConnection($connection);
foreach ($params as $key => $value) {
$transport->setParam($key, $value);
}
} else {
throw new InvalidException('Invalid transport');
}
return $transport;
}
|
php
|
public static function create($transport, Connection $connection, array $params = []): AbstractTransport
{
if (\is_array($transport) && isset($transport['type'])) {
$transportParams = $transport;
unset($transportParams['type']);
$params = \array_replace($params, $transportParams);
$transport = $transport['type'];
}
if (\is_string($transport)) {
$specialTransports = [
'httpadapter' => 'HttpAdapter',
'nulltransport' => 'NullTransport',
];
if (isset($specialTransports[\strtolower($transport)])) {
$transport = $specialTransports[\strtolower($transport)];
} else {
$transport = \ucfirst($transport);
}
$classNames = ["Elastica\\Transport\\$transport", $transport];
foreach ($classNames as $className) {
if (\class_exists($className)) {
$transport = new $className();
break;
}
}
}
if ($transport instanceof self) {
$transport->setConnection($connection);
foreach ($params as $key => $value) {
$transport->setParam($key, $value);
}
} else {
throw new InvalidException('Invalid transport');
}
return $transport;
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"transport",
",",
"Connection",
"$",
"connection",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
":",
"AbstractTransport",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"transport",
")",
"&&",
"isset",
"(",
"$",
"transport",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"transportParams",
"=",
"$",
"transport",
";",
"unset",
"(",
"$",
"transportParams",
"[",
"'type'",
"]",
")",
";",
"$",
"params",
"=",
"\\",
"array_replace",
"(",
"$",
"params",
",",
"$",
"transportParams",
")",
";",
"$",
"transport",
"=",
"$",
"transport",
"[",
"'type'",
"]",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"transport",
")",
")",
"{",
"$",
"specialTransports",
"=",
"[",
"'httpadapter'",
"=>",
"'HttpAdapter'",
",",
"'nulltransport'",
"=>",
"'NullTransport'",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"specialTransports",
"[",
"\\",
"strtolower",
"(",
"$",
"transport",
")",
"]",
")",
")",
"{",
"$",
"transport",
"=",
"$",
"specialTransports",
"[",
"\\",
"strtolower",
"(",
"$",
"transport",
")",
"]",
";",
"}",
"else",
"{",
"$",
"transport",
"=",
"\\",
"ucfirst",
"(",
"$",
"transport",
")",
";",
"}",
"$",
"classNames",
"=",
"[",
"\"Elastica\\\\Transport\\\\$transport\"",
",",
"$",
"transport",
"]",
";",
"foreach",
"(",
"$",
"classNames",
"as",
"$",
"className",
")",
"{",
"if",
"(",
"\\",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"$",
"transport",
"=",
"new",
"$",
"className",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"transport",
"instanceof",
"self",
")",
"{",
"$",
"transport",
"->",
"setConnection",
"(",
"$",
"connection",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"transport",
"->",
"setParam",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Invalid transport'",
")",
";",
"}",
"return",
"$",
"transport",
";",
"}"
] |
Create a transport.
The $transport parameter can be one of the following values:
* string: The short name of a transport. For instance "Http"
* object: An already instantiated instance of a transport
* array: An array with a "type" key which must be set to one of the two options. All other
keys in the array will be set as parameters in the transport instance
@param mixed $transport A transport definition
@param Connection $connection A connection instance
@param array $params Parameters for the transport class
@throws InvalidException
@return AbstractTransport
|
[
"Create",
"a",
"transport",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Transport/AbstractTransport.php#L102-L143
|
train
|
ruflin/Elastica
|
lib/Elastica/Transport/Guzzle.php
|
Guzzle._getGuzzleClient
|
protected function _getGuzzleClient(bool $persistent = true): Client
{
if (!$persistent || !self::$_guzzleClientConnection) {
self::$_guzzleClientConnection = new Client();
}
return self::$_guzzleClientConnection;
}
|
php
|
protected function _getGuzzleClient(bool $persistent = true): Client
{
if (!$persistent || !self::$_guzzleClientConnection) {
self::$_guzzleClientConnection = new Client();
}
return self::$_guzzleClientConnection;
}
|
[
"protected",
"function",
"_getGuzzleClient",
"(",
"bool",
"$",
"persistent",
"=",
"true",
")",
":",
"Client",
"{",
"if",
"(",
"!",
"$",
"persistent",
"||",
"!",
"self",
"::",
"$",
"_guzzleClientConnection",
")",
"{",
"self",
"::",
"$",
"_guzzleClientConnection",
"=",
"new",
"Client",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_guzzleClientConnection",
";",
"}"
] |
Return Guzzle resource.
@param bool $persistent False if not persistent connection
@return Client
|
[
"Return",
"Guzzle",
"resource",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Transport/Guzzle.php#L161-L168
|
train
|
ruflin/Elastica
|
lib/Elastica/Transport/Guzzle.php
|
Guzzle._getBaseUrl
|
protected function _getBaseUrl(Connection $connection): string
{
// If url is set, url is taken. Otherwise port, host and path
$url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';
if (!empty($url)) {
$baseUri = $url;
} else {
$baseUri = (string) Uri::fromParts([
'scheme' => $this->_scheme,
'host' => $connection->getHost(),
'port' => $connection->getPort(),
'path' => \ltrim('/', $connection->getPath()),
]);
}
return \rtrim($baseUri, '/');
}
|
php
|
protected function _getBaseUrl(Connection $connection): string
{
// If url is set, url is taken. Otherwise port, host and path
$url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';
if (!empty($url)) {
$baseUri = $url;
} else {
$baseUri = (string) Uri::fromParts([
'scheme' => $this->_scheme,
'host' => $connection->getHost(),
'port' => $connection->getPort(),
'path' => \ltrim('/', $connection->getPath()),
]);
}
return \rtrim($baseUri, '/');
}
|
[
"protected",
"function",
"_getBaseUrl",
"(",
"Connection",
"$",
"connection",
")",
":",
"string",
"{",
"// If url is set, url is taken. Otherwise port, host and path",
"$",
"url",
"=",
"$",
"connection",
"->",
"hasConfig",
"(",
"'url'",
")",
"?",
"$",
"connection",
"->",
"getConfig",
"(",
"'url'",
")",
":",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"url",
")",
")",
"{",
"$",
"baseUri",
"=",
"$",
"url",
";",
"}",
"else",
"{",
"$",
"baseUri",
"=",
"(",
"string",
")",
"Uri",
"::",
"fromParts",
"(",
"[",
"'scheme'",
"=>",
"$",
"this",
"->",
"_scheme",
",",
"'host'",
"=>",
"$",
"connection",
"->",
"getHost",
"(",
")",
",",
"'port'",
"=>",
"$",
"connection",
"->",
"getPort",
"(",
")",
",",
"'path'",
"=>",
"\\",
"ltrim",
"(",
"'/'",
",",
"$",
"connection",
"->",
"getPath",
"(",
")",
")",
",",
"]",
")",
";",
"}",
"return",
"\\",
"rtrim",
"(",
"$",
"baseUri",
",",
"'/'",
")",
";",
"}"
] |
Builds the base url for the guzzle connection.
@param Connection $connection
@return string
|
[
"Builds",
"the",
"base",
"url",
"for",
"the",
"guzzle",
"connection",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Transport/Guzzle.php#L177-L194
|
train
|
ruflin/Elastica
|
lib/Elastica/Transport/Guzzle.php
|
Guzzle._getActionPath
|
protected function _getActionPath(Request $request): string
{
$action = $request->getPath();
if ($action) {
$action = '/'.\ltrim($action, '/');
}
if (!Util::isDateMathEscaped($action)) {
$action = Util::escapeDateMath($action);
}
$query = $request->getQuery();
if (!empty($query)) {
$action .= '?'.\http_build_query(
$this->sanityzeQueryStringBool($query)
);
}
return $action;
}
|
php
|
protected function _getActionPath(Request $request): string
{
$action = $request->getPath();
if ($action) {
$action = '/'.\ltrim($action, '/');
}
if (!Util::isDateMathEscaped($action)) {
$action = Util::escapeDateMath($action);
}
$query = $request->getQuery();
if (!empty($query)) {
$action .= '?'.\http_build_query(
$this->sanityzeQueryStringBool($query)
);
}
return $action;
}
|
[
"protected",
"function",
"_getActionPath",
"(",
"Request",
"$",
"request",
")",
":",
"string",
"{",
"$",
"action",
"=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"action",
")",
"{",
"$",
"action",
"=",
"'/'",
".",
"\\",
"ltrim",
"(",
"$",
"action",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"!",
"Util",
"::",
"isDateMathEscaped",
"(",
"$",
"action",
")",
")",
"{",
"$",
"action",
"=",
"Util",
"::",
"escapeDateMath",
"(",
"$",
"action",
")",
";",
"}",
"$",
"query",
"=",
"$",
"request",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"query",
")",
")",
"{",
"$",
"action",
".=",
"'?'",
".",
"\\",
"http_build_query",
"(",
"$",
"this",
"->",
"sanityzeQueryStringBool",
"(",
"$",
"query",
")",
")",
";",
"}",
"return",
"$",
"action",
";",
"}"
] |
Builds the action path url for each request.
@param Request $request
@return string
|
[
"Builds",
"the",
"action",
"path",
"url",
"for",
"each",
"request",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Transport/Guzzle.php#L203-L223
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldParam
|
public function setFieldParam(string $field, string $key, string $value): self
{
if (!isset($this->_params[$field])) {
$this->_params[$field] = [];
}
$this->_params[$field][$key] = $value;
return $this;
}
|
php
|
public function setFieldParam(string $field, string $key, string $value): self
{
if (!isset($this->_params[$field])) {
$this->_params[$field] = [];
}
$this->_params[$field][$key] = $value;
return $this;
}
|
[
"public",
"function",
"setFieldParam",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"key",
",",
"string",
"$",
"value",
")",
":",
"self",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_params",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_params",
"[",
"$",
"field",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"_params",
"[",
"$",
"field",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets a param for the given field.
@param string $field
@param string $key
@param string $value
@return $this
|
[
"Sets",
"a",
"param",
"for",
"the",
"given",
"field",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L56-L65
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldOperator
|
public function setFieldOperator(string $field, string $operator = self::OPERATOR_OR): self
{
return $this->setFieldParam($field, 'operator', $operator);
}
|
php
|
public function setFieldOperator(string $field, string $operator = self::OPERATOR_OR): self
{
return $this->setFieldParam($field, 'operator', $operator);
}
|
[
"public",
"function",
"setFieldOperator",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"operator",
"=",
"self",
"::",
"OPERATOR_OR",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setFieldParam",
"(",
"$",
"field",
",",
"'operator'",
",",
"$",
"operator",
")",
";",
"}"
] |
Set field operator.
@param string $field
@param string $operator
@return $this
|
[
"Set",
"field",
"operator",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L88-L91
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldAnalyzer
|
public function setFieldAnalyzer(string $field, string $analyzer): self
{
return $this->setFieldParam($field, 'analyzer', $analyzer);
}
|
php
|
public function setFieldAnalyzer(string $field, string $analyzer): self
{
return $this->setFieldParam($field, 'analyzer', $analyzer);
}
|
[
"public",
"function",
"setFieldAnalyzer",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"analyzer",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setFieldParam",
"(",
"$",
"field",
",",
"'analyzer'",
",",
"$",
"analyzer",
")",
";",
"}"
] |
Set field analyzer.
@param string $field
@param string $analyzer
@return $this
|
[
"Set",
"field",
"analyzer",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L101-L104
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldBoost
|
public function setFieldBoost(string $field, float $boost = 1.0): self
{
return $this->setFieldParam($field, 'boost', $boost);
}
|
php
|
public function setFieldBoost(string $field, float $boost = 1.0): self
{
return $this->setFieldParam($field, 'boost', $boost);
}
|
[
"public",
"function",
"setFieldBoost",
"(",
"string",
"$",
"field",
",",
"float",
"$",
"boost",
"=",
"1.0",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setFieldParam",
"(",
"$",
"field",
",",
"'boost'",
",",
"$",
"boost",
")",
";",
"}"
] |
Set field boost value.
If not set, defaults to 1.0.
@param string $field
@param float $boost
@return $this
|
[
"Set",
"field",
"boost",
"value",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L116-L119
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldFuzzyRewrite
|
public function setFieldFuzzyRewrite(string $field, string $fuzzyRewrite): self
{
return $this->setFieldParam($field, 'fuzzy_rewrite', $fuzzyRewrite);
}
|
php
|
public function setFieldFuzzyRewrite(string $field, string $fuzzyRewrite): self
{
return $this->setFieldParam($field, 'fuzzy_rewrite', $fuzzyRewrite);
}
|
[
"public",
"function",
"setFieldFuzzyRewrite",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"fuzzyRewrite",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setFieldParam",
"(",
"$",
"field",
",",
"'fuzzy_rewrite'",
",",
"$",
"fuzzyRewrite",
")",
";",
"}"
] |
Set field fuzzy rewrite.
@param string $field
@param string $fuzzyRewrite
@return $this
|
[
"Set",
"field",
"fuzzy",
"rewrite",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L157-L160
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldPrefixLength
|
public function setFieldPrefixLength(string $field, int $prefixLength): self
{
return $this->setFieldParam($field, 'prefix_length', $prefixLength);
}
|
php
|
public function setFieldPrefixLength(string $field, int $prefixLength): self
{
return $this->setFieldParam($field, 'prefix_length', $prefixLength);
}
|
[
"public",
"function",
"setFieldPrefixLength",
"(",
"string",
"$",
"field",
",",
"int",
"$",
"prefixLength",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setFieldParam",
"(",
"$",
"field",
",",
"'prefix_length'",
",",
"$",
"prefixLength",
")",
";",
"}"
] |
Set field prefix length.
@param string $field
@param int $prefixLength
@return $this
|
[
"Set",
"field",
"prefix",
"length",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L170-L173
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldMaxExpansions
|
public function setFieldMaxExpansions(string $field, int $maxExpansions): self
{
return $this->setFieldParam($field, 'max_expansions', $maxExpansions);
}
|
php
|
public function setFieldMaxExpansions(string $field, int $maxExpansions): self
{
return $this->setFieldParam($field, 'max_expansions', $maxExpansions);
}
|
[
"public",
"function",
"setFieldMaxExpansions",
"(",
"string",
"$",
"field",
",",
"int",
"$",
"maxExpansions",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setFieldParam",
"(",
"$",
"field",
",",
"'max_expansions'",
",",
"$",
"maxExpansions",
")",
";",
"}"
] |
Set field max expansions.
@param string $field
@param int $maxExpansions
@return $this
|
[
"Set",
"field",
"max",
"expansions",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L183-L186
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldZeroTermsQuery
|
public function setFieldZeroTermsQuery(string $field, string $zeroTermQuery = self::ZERO_TERM_NONE): self
{
return $this->setFieldParam($field, 'zero_terms_query', $zeroTermQuery);
}
|
php
|
public function setFieldZeroTermsQuery(string $field, string $zeroTermQuery = self::ZERO_TERM_NONE): self
{
return $this->setFieldParam($field, 'zero_terms_query', $zeroTermQuery);
}
|
[
"public",
"function",
"setFieldZeroTermsQuery",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"zeroTermQuery",
"=",
"self",
"::",
"ZERO_TERM_NONE",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setFieldParam",
"(",
"$",
"field",
",",
"'zero_terms_query'",
",",
"$",
"zeroTermQuery",
")",
";",
"}"
] |
Set zero terms query.
If not set, default to 'none'
@param string $field
@param string $zeroTermQuery
@return $this
|
[
"Set",
"zero",
"terms",
"query",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L198-L201
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Match.php
|
Match.setFieldCutoffFrequency
|
public function setFieldCutoffFrequency(string $field, float $cutoffFrequency): self
{
return $this->setFieldParam($field, 'cutoff_frequency', $cutoffFrequency);
}
|
php
|
public function setFieldCutoffFrequency(string $field, float $cutoffFrequency): self
{
return $this->setFieldParam($field, 'cutoff_frequency', $cutoffFrequency);
}
|
[
"public",
"function",
"setFieldCutoffFrequency",
"(",
"string",
"$",
"field",
",",
"float",
"$",
"cutoffFrequency",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setFieldParam",
"(",
"$",
"field",
",",
"'cutoff_frequency'",
",",
"$",
"cutoffFrequency",
")",
";",
"}"
] |
Set cutoff frequency.
@param string $field
@param float $cutoffFrequency
@return $this
|
[
"Set",
"cutoff",
"frequency",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Match.php#L211-L214
|
train
|
ruflin/Elastica
|
lib/Elastica/Bulk.php
|
Bulk.setRequestParam
|
public function setRequestParam(string $name, $value): self
{
$this->_requestParams[$name] = $value;
return $this;
}
|
php
|
public function setRequestParam(string $name, $value): self
{
$this->_requestParams[$name] = $value;
return $this;
}
|
[
"public",
"function",
"setRequestParam",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"_requestParams",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] |
Set a url parameter on the request bulk request.
@param string $name name of the parameter
@param mixed $value value of the parameter
@return $this
|
[
"Set",
"a",
"url",
"parameter",
"on",
"the",
"request",
"bulk",
"request",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Bulk.php#L295-L300
|
train
|
ruflin/Elastica
|
lib/Elastica/Bulk/Action/AbstractDocument.php
|
AbstractDocument.create
|
public static function create($data, string $opType = null): self
{
//Check type
if (!$data instanceof Document && !$data instanceof AbstractScript) {
throw new \InvalidArgumentException('The data needs to be a Document or a Script.');
}
if (null === $opType && $data->hasOpType()) {
$opType = $data->getOpType();
}
//Check that scripts can only be used for updates
if ($data instanceof AbstractScript) {
if (null === $opType) {
$opType = self::OP_TYPE_UPDATE;
} elseif (self::OP_TYPE_UPDATE !== $opType) {
throw new \InvalidArgumentException('Scripts can only be used with the update operation type.');
}
}
switch ($opType) {
case self::OP_TYPE_DELETE:
$action = new DeleteDocument($data);
break;
case self::OP_TYPE_CREATE:
$action = new CreateDocument($data);
break;
case self::OP_TYPE_UPDATE:
$action = new UpdateDocument($data);
break;
case self::OP_TYPE_INDEX:
default:
$action = new IndexDocument($data);
break;
}
return $action;
}
|
php
|
public static function create($data, string $opType = null): self
{
//Check type
if (!$data instanceof Document && !$data instanceof AbstractScript) {
throw new \InvalidArgumentException('The data needs to be a Document or a Script.');
}
if (null === $opType && $data->hasOpType()) {
$opType = $data->getOpType();
}
//Check that scripts can only be used for updates
if ($data instanceof AbstractScript) {
if (null === $opType) {
$opType = self::OP_TYPE_UPDATE;
} elseif (self::OP_TYPE_UPDATE !== $opType) {
throw new \InvalidArgumentException('Scripts can only be used with the update operation type.');
}
}
switch ($opType) {
case self::OP_TYPE_DELETE:
$action = new DeleteDocument($data);
break;
case self::OP_TYPE_CREATE:
$action = new CreateDocument($data);
break;
case self::OP_TYPE_UPDATE:
$action = new UpdateDocument($data);
break;
case self::OP_TYPE_INDEX:
default:
$action = new IndexDocument($data);
break;
}
return $action;
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"data",
",",
"string",
"$",
"opType",
"=",
"null",
")",
":",
"self",
"{",
"//Check type",
"if",
"(",
"!",
"$",
"data",
"instanceof",
"Document",
"&&",
"!",
"$",
"data",
"instanceof",
"AbstractScript",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The data needs to be a Document or a Script.'",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"opType",
"&&",
"$",
"data",
"->",
"hasOpType",
"(",
")",
")",
"{",
"$",
"opType",
"=",
"$",
"data",
"->",
"getOpType",
"(",
")",
";",
"}",
"//Check that scripts can only be used for updates",
"if",
"(",
"$",
"data",
"instanceof",
"AbstractScript",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"opType",
")",
"{",
"$",
"opType",
"=",
"self",
"::",
"OP_TYPE_UPDATE",
";",
"}",
"elseif",
"(",
"self",
"::",
"OP_TYPE_UPDATE",
"!==",
"$",
"opType",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Scripts can only be used with the update operation type.'",
")",
";",
"}",
"}",
"switch",
"(",
"$",
"opType",
")",
"{",
"case",
"self",
"::",
"OP_TYPE_DELETE",
":",
"$",
"action",
"=",
"new",
"DeleteDocument",
"(",
"$",
"data",
")",
";",
"break",
";",
"case",
"self",
"::",
"OP_TYPE_CREATE",
":",
"$",
"action",
"=",
"new",
"CreateDocument",
"(",
"$",
"data",
")",
";",
"break",
";",
"case",
"self",
"::",
"OP_TYPE_UPDATE",
":",
"$",
"action",
"=",
"new",
"UpdateDocument",
"(",
"$",
"data",
")",
";",
"break",
";",
"case",
"self",
"::",
"OP_TYPE_INDEX",
":",
"default",
":",
"$",
"action",
"=",
"new",
"IndexDocument",
"(",
"$",
"data",
")",
";",
"break",
";",
"}",
"return",
"$",
"action",
";",
"}"
] |
Creates a bulk action for a document or a script.
The action can be index, update, create or delete based on the $opType param (by default index).
@param Document|AbstractScript $data
@param string $opType
@return static
|
[
"Creates",
"a",
"bulk",
"action",
"for",
"a",
"document",
"or",
"a",
"script",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Bulk/Action/AbstractDocument.php#L133-L173
|
train
|
ruflin/Elastica
|
lib/Elastica/Node/Info.php
|
Info.get
|
public function get()
{
$data = $this->getData();
foreach (\func_get_args() as $arg) {
if (isset($data[$arg])) {
$data = $data[$arg];
} else {
return null;
}
}
return $data;
}
|
php
|
public function get()
{
$data = $this->getData();
foreach (\func_get_args() as $arg) {
if (isset($data[$arg])) {
$data = $data[$arg];
} else {
return null;
}
}
return $data;
}
|
[
"public",
"function",
"get",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"foreach",
"(",
"\\",
"func_get_args",
"(",
")",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"arg",
"]",
")",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"[",
"$",
"arg",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Returns the entry in the data array based on the params.
Several params possible.
Example 1: get('os', 'mem', 'total') returns total memory of the system the
node is running on
Example 2: get('os', 'mem') returns an array with all mem infos
@return mixed Data array entry or null if not found
|
[
"Returns",
"the",
"entry",
"in",
"the",
"data",
"array",
"based",
"on",
"the",
"params",
".",
"Several",
"params",
"possible",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Node/Info.php#L74-L87
|
train
|
ruflin/Elastica
|
lib/Elastica/Node/Info.php
|
Info.getPort
|
public function getPort(): string
{
// Returns string in format: inet[/192.168.1.115:9201]
$data = $this->get('http_address');
$data = \substr($data, 6, \strlen($data) - 7);
$data = \explode(':', $data);
return $data[1];
}
|
php
|
public function getPort(): string
{
// Returns string in format: inet[/192.168.1.115:9201]
$data = $this->get('http_address');
$data = \substr($data, 6, \strlen($data) - 7);
$data = \explode(':', $data);
return $data[1];
}
|
[
"public",
"function",
"getPort",
"(",
")",
":",
"string",
"{",
"// Returns string in format: inet[/192.168.1.115:9201]",
"$",
"data",
"=",
"$",
"this",
"->",
"get",
"(",
"'http_address'",
")",
";",
"$",
"data",
"=",
"\\",
"substr",
"(",
"$",
"data",
",",
"6",
",",
"\\",
"strlen",
"(",
"$",
"data",
")",
"-",
"7",
")",
";",
"$",
"data",
"=",
"\\",
"explode",
"(",
"':'",
",",
"$",
"data",
")",
";",
"return",
"$",
"data",
"[",
"1",
"]",
";",
"}"
] |
Return port of the node.
@return string Returns Node port
|
[
"Return",
"port",
"of",
"the",
"node",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Node/Info.php#L94-L102
|
train
|
ruflin/Elastica
|
lib/Elastica/Node/Info.php
|
Info.getIp
|
public function getIp(): string
{
// Returns string in format: inet[/192.168.1.115:9201]
$data = $this->get('http_address');
$data = \substr($data, 6, \strlen($data) - 7);
$data = \explode(':', $data);
return $data[0];
}
|
php
|
public function getIp(): string
{
// Returns string in format: inet[/192.168.1.115:9201]
$data = $this->get('http_address');
$data = \substr($data, 6, \strlen($data) - 7);
$data = \explode(':', $data);
return $data[0];
}
|
[
"public",
"function",
"getIp",
"(",
")",
":",
"string",
"{",
"// Returns string in format: inet[/192.168.1.115:9201]",
"$",
"data",
"=",
"$",
"this",
"->",
"get",
"(",
"'http_address'",
")",
";",
"$",
"data",
"=",
"\\",
"substr",
"(",
"$",
"data",
",",
"6",
",",
"\\",
"strlen",
"(",
"$",
"data",
")",
"-",
"7",
")",
";",
"$",
"data",
"=",
"\\",
"explode",
"(",
"':'",
",",
"$",
"data",
")",
";",
"return",
"$",
"data",
"[",
"0",
"]",
";",
"}"
] |
Return IP of the node.
@return string Returns Node ip address
|
[
"Return",
"IP",
"of",
"the",
"node",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Node/Info.php#L109-L117
|
train
|
ruflin/Elastica
|
lib/Elastica/Node/Info.php
|
Info.getPlugins
|
public function getPlugins(): array
{
if (!\in_array('plugins', $this->_params, true)) {
//Plugin data was not retrieved when refresh() was called last. Get it now.
$this->_params[] = 'plugins';
$this->refresh($this->_params);
}
return $this->get('plugins');
}
|
php
|
public function getPlugins(): array
{
if (!\in_array('plugins', $this->_params, true)) {
//Plugin data was not retrieved when refresh() was called last. Get it now.
$this->_params[] = 'plugins';
$this->refresh($this->_params);
}
return $this->get('plugins');
}
|
[
"public",
"function",
"getPlugins",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"'plugins'",
",",
"$",
"this",
"->",
"_params",
",",
"true",
")",
")",
"{",
"//Plugin data was not retrieved when refresh() was called last. Get it now.",
"$",
"this",
"->",
"_params",
"[",
"]",
"=",
"'plugins'",
";",
"$",
"this",
"->",
"refresh",
"(",
"$",
"this",
"->",
"_params",
")",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"'plugins'",
")",
";",
"}"
] |
Return data regarding plugins installed on this node.
@return array plugin data
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-info.html
|
[
"Return",
"data",
"regarding",
"plugins",
"installed",
"on",
"this",
"node",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Node/Info.php#L126-L135
|
train
|
ruflin/Elastica
|
lib/Elastica/Node/Info.php
|
Info.hasPlugin
|
public function hasPlugin($name): bool
{
foreach ($this->getPlugins() as $plugin) {
if ($plugin['name'] === $name) {
return true;
}
}
return false;
}
|
php
|
public function hasPlugin($name): bool
{
foreach ($this->getPlugins() as $plugin) {
if ($plugin['name'] === $name) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"hasPlugin",
"(",
"$",
"name",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getPlugins",
"(",
")",
"as",
"$",
"plugin",
")",
"{",
"if",
"(",
"$",
"plugin",
"[",
"'name'",
"]",
"===",
"$",
"name",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if the given plugin is installed on this node.
@param string $name plugin name
@return bool true if the plugin is installed, false otherwise
|
[
"Check",
"if",
"the",
"given",
"plugin",
"is",
"installed",
"on",
"this",
"node",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Node/Info.php#L144-L153
|
train
|
ruflin/Elastica
|
lib/Elastica/Node.php
|
Node.getName
|
public function getName()
{
if (empty($this->_name)) {
$this->_name = $this->getInfo()->getName();
}
return $this->_name;
}
|
php
|
public function getName()
{
if (empty($this->_name)) {
$this->_name = $this->getInfo()->getName();
}
return $this->_name;
}
|
[
"public",
"function",
"getName",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_name",
")",
")",
"{",
"$",
"this",
"->",
"_name",
"=",
"$",
"this",
"->",
"getInfo",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_name",
";",
"}"
] |
Get the name of the node.
@return string Node name
|
[
"Get",
"the",
"name",
"of",
"the",
"node",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Node.php#L85-L92
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.addDocument
|
public function addDocument(Document $doc)
{
$endpoint = new \Elasticsearch\Endpoints\Index();
if (null !== $doc->getId() && '' !== $doc->getId()) {
$endpoint->setID($doc->getId());
}
$options = $doc->getOptions(
[
'version',
'version_type',
'routing',
'percolate',
'parent',
'op_type',
'consistency',
'replication',
'refresh',
'timeout',
'pipeline',
]
);
$endpoint->setBody($doc->getData());
$endpoint->setParams($options);
$response = $this->requestEndpoint($endpoint);
$data = $response->getData();
// set autogenerated id to document
if (($doc->isAutoPopulate()
|| $this->getIndex()->getClient()->getConfigValue(['document', 'autoPopulate'], false))
&& $response->isOk()
) {
if (!$doc->hasId()) {
if (isset($data['_id'])) {
$doc->setId($data['_id']);
}
}
if (isset($data['_version'])) {
$doc->setVersion($data['_version']);
}
}
return $response;
}
|
php
|
public function addDocument(Document $doc)
{
$endpoint = new \Elasticsearch\Endpoints\Index();
if (null !== $doc->getId() && '' !== $doc->getId()) {
$endpoint->setID($doc->getId());
}
$options = $doc->getOptions(
[
'version',
'version_type',
'routing',
'percolate',
'parent',
'op_type',
'consistency',
'replication',
'refresh',
'timeout',
'pipeline',
]
);
$endpoint->setBody($doc->getData());
$endpoint->setParams($options);
$response = $this->requestEndpoint($endpoint);
$data = $response->getData();
// set autogenerated id to document
if (($doc->isAutoPopulate()
|| $this->getIndex()->getClient()->getConfigValue(['document', 'autoPopulate'], false))
&& $response->isOk()
) {
if (!$doc->hasId()) {
if (isset($data['_id'])) {
$doc->setId($data['_id']);
}
}
if (isset($data['_version'])) {
$doc->setVersion($data['_version']);
}
}
return $response;
}
|
[
"public",
"function",
"addDocument",
"(",
"Document",
"$",
"doc",
")",
"{",
"$",
"endpoint",
"=",
"new",
"\\",
"Elasticsearch",
"\\",
"Endpoints",
"\\",
"Index",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"doc",
"->",
"getId",
"(",
")",
"&&",
"''",
"!==",
"$",
"doc",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"endpoint",
"->",
"setID",
"(",
"$",
"doc",
"->",
"getId",
"(",
")",
")",
";",
"}",
"$",
"options",
"=",
"$",
"doc",
"->",
"getOptions",
"(",
"[",
"'version'",
",",
"'version_type'",
",",
"'routing'",
",",
"'percolate'",
",",
"'parent'",
",",
"'op_type'",
",",
"'consistency'",
",",
"'replication'",
",",
"'refresh'",
",",
"'timeout'",
",",
"'pipeline'",
",",
"]",
")",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"doc",
"->",
"getData",
"(",
")",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"options",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"$",
"data",
"=",
"$",
"response",
"->",
"getData",
"(",
")",
";",
"// set autogenerated id to document",
"if",
"(",
"(",
"$",
"doc",
"->",
"isAutoPopulate",
"(",
")",
"||",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"getClient",
"(",
")",
"->",
"getConfigValue",
"(",
"[",
"'document'",
",",
"'autoPopulate'",
"]",
",",
"false",
")",
")",
"&&",
"$",
"response",
"->",
"isOk",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"doc",
"->",
"hasId",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
")",
"{",
"$",
"doc",
"->",
"setId",
"(",
"$",
"data",
"[",
"'_id'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'_version'",
"]",
")",
")",
"{",
"$",
"doc",
"->",
"setVersion",
"(",
"$",
"data",
"[",
"'_version'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] |
Adds the given document to the search index.
@param \Elastica\Document $doc Document with data
@return \Elastica\Response
|
[
"Adds",
"the",
"given",
"document",
"to",
"the",
"search",
"index",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L66-L112
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.getDocument
|
public function getDocument($id, array $options = [])
{
$endpoint = new \Elasticsearch\Endpoints\Get();
$endpoint->setID($id);
$endpoint->setParams($options);
$response = $this->requestEndpoint($endpoint);
$result = $response->getData();
if (!isset($result['found']) || false === $result['found']) {
throw new NotFoundException('doc id '.$id.' not found');
}
if (isset($result['fields'])) {
$data = $result['fields'];
} elseif (isset($result['_source'])) {
$data = $result['_source'];
} else {
$data = [];
}
$document = new Document($id, $data, $this->getName(), $this->getIndex());
$document->setVersion($result['_version']);
return $document;
}
|
php
|
public function getDocument($id, array $options = [])
{
$endpoint = new \Elasticsearch\Endpoints\Get();
$endpoint->setID($id);
$endpoint->setParams($options);
$response = $this->requestEndpoint($endpoint);
$result = $response->getData();
if (!isset($result['found']) || false === $result['found']) {
throw new NotFoundException('doc id '.$id.' not found');
}
if (isset($result['fields'])) {
$data = $result['fields'];
} elseif (isset($result['_source'])) {
$data = $result['_source'];
} else {
$data = [];
}
$document = new Document($id, $data, $this->getName(), $this->getIndex());
$document->setVersion($result['_version']);
return $document;
}
|
[
"public",
"function",
"getDocument",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"endpoint",
"=",
"new",
"\\",
"Elasticsearch",
"\\",
"Endpoints",
"\\",
"Get",
"(",
")",
";",
"$",
"endpoint",
"->",
"setID",
"(",
"$",
"id",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"options",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"$",
"result",
"=",
"$",
"response",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"'found'",
"]",
")",
"||",
"false",
"===",
"$",
"result",
"[",
"'found'",
"]",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"'doc id '",
".",
"$",
"id",
".",
"' not found'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'fields'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"$",
"result",
"[",
"'fields'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"result",
"[",
"'_source'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"$",
"result",
"[",
"'_source'",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"}",
"$",
"document",
"=",
"new",
"Document",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"getIndex",
"(",
")",
")",
";",
"$",
"document",
"->",
"setVersion",
"(",
"$",
"result",
"[",
"'_version'",
"]",
")",
";",
"return",
"$",
"document",
";",
"}"
] |
Get the document from search index.
@param int|string $id Document id
@param array $options options for the get request
@throws \Elastica\Exception\NotFoundException
@throws \Elastica\Exception\ResponseException
@return \Elastica\Document
|
[
"Get",
"the",
"document",
"from",
"search",
"index",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L245-L270
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.setMapping
|
public function setMapping($mapping, array $query = [])
{
$mapping = Mapping::create($mapping);
$mapping->setType($this);
return $mapping->send($query);
}
|
php
|
public function setMapping($mapping, array $query = [])
{
$mapping = Mapping::create($mapping);
$mapping->setType($this);
return $mapping->send($query);
}
|
[
"public",
"function",
"setMapping",
"(",
"$",
"mapping",
",",
"array",
"$",
"query",
"=",
"[",
"]",
")",
"{",
"$",
"mapping",
"=",
"Mapping",
"::",
"create",
"(",
"$",
"mapping",
")",
";",
"$",
"mapping",
"->",
"setType",
"(",
"$",
"this",
")",
";",
"return",
"$",
"mapping",
"->",
"send",
"(",
"$",
"query",
")",
";",
"}"
] |
Sets value type mapping for this type.
@param \Elastica\Type\Mapping|array $mapping Elastica\Type\MappingType object or property array with all mappings
@param array $query querystring when put mapping (for example update_all_types)
@return \Elastica\Response
|
[
"Sets",
"value",
"type",
"mapping",
"for",
"this",
"type",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L304-L310
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.getMapping
|
public function getMapping()
{
$response = $this->requestEndpoint(new Get());
$data = $response->getData();
$mapping = \array_shift($data);
if (isset($mapping['mappings'])) {
return $mapping['mappings'];
}
return [];
}
|
php
|
public function getMapping()
{
$response = $this->requestEndpoint(new Get());
$data = $response->getData();
$mapping = \array_shift($data);
if (isset($mapping['mappings'])) {
return $mapping['mappings'];
}
return [];
}
|
[
"public",
"function",
"getMapping",
"(",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"requestEndpoint",
"(",
"new",
"Get",
"(",
")",
")",
";",
"$",
"data",
"=",
"$",
"response",
"->",
"getData",
"(",
")",
";",
"$",
"mapping",
"=",
"\\",
"array_shift",
"(",
"$",
"data",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'mappings'",
"]",
")",
")",
"{",
"return",
"$",
"mapping",
"[",
"'mappings'",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
] |
Returns current mapping for the given type.
@return array Current mapping
|
[
"Returns",
"current",
"mapping",
"for",
"the",
"given",
"type",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L317-L328
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.createSearch
|
public function createSearch($query = '', $options = null, BuilderInterface $builder = null)
{
$search = $this->getIndex()->createSearch($query, $options, $builder);
$search->addType($this);
return $search;
}
|
php
|
public function createSearch($query = '', $options = null, BuilderInterface $builder = null)
{
$search = $this->getIndex()->createSearch($query, $options, $builder);
$search->addType($this);
return $search;
}
|
[
"public",
"function",
"createSearch",
"(",
"$",
"query",
"=",
"''",
",",
"$",
"options",
"=",
"null",
",",
"BuilderInterface",
"$",
"builder",
"=",
"null",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"createSearch",
"(",
"$",
"query",
",",
"$",
"options",
",",
"$",
"builder",
")",
";",
"$",
"search",
"->",
"addType",
"(",
"$",
"this",
")",
";",
"return",
"$",
"search",
";",
"}"
] |
Create search object.
@param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object
@param int|array $options OPTIONAL Limit or associative array of options (option=>value)
@param BuilderInterface $builder
@return Search
|
[
"Create",
"search",
"object",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L339-L345
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.search
|
public function search($query = '', $options = null)
{
$search = $this->createSearch($query, $options);
return $search->search();
}
|
php
|
public function search($query = '', $options = null)
{
$search = $this->createSearch($query, $options);
return $search->search();
}
|
[
"public",
"function",
"search",
"(",
"$",
"query",
"=",
"''",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"createSearch",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"return",
"$",
"search",
"->",
"search",
"(",
")",
";",
"}"
] |
Do a search on this type.
@param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object
@param int|array $options OPTIONAL Limit or associative array of options (option=>value)
@return \Elastica\ResultSet with all results inside
@see \Elastica\SearchableInterface::search
|
[
"Do",
"a",
"search",
"on",
"this",
"type",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L357-L362
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.deleteById
|
public function deleteById($id, array $options = [])
{
if (empty($id) || !\trim($id)) {
throw new \InvalidArgumentException();
}
$endpoint = new Delete();
$endpoint->setID($id);
$endpoint->setParams($options);
$response = $this->requestEndpoint($endpoint);
$responseData = $response->getData();
if (isset($responseData['result']) && 'not_found' == $responseData['result']) {
throw new NotFoundException('Doc id '.$id.' not found and can not be deleted');
}
return $response;
}
|
php
|
public function deleteById($id, array $options = [])
{
if (empty($id) || !\trim($id)) {
throw new \InvalidArgumentException();
}
$endpoint = new Delete();
$endpoint->setID($id);
$endpoint->setParams($options);
$response = $this->requestEndpoint($endpoint);
$responseData = $response->getData();
if (isset($responseData['result']) && 'not_found' == $responseData['result']) {
throw new NotFoundException('Doc id '.$id.' not found and can not be deleted');
}
return $response;
}
|
[
"public",
"function",
"deleteById",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"||",
"!",
"\\",
"trim",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"endpoint",
"=",
"new",
"Delete",
"(",
")",
";",
"$",
"endpoint",
"->",
"setID",
"(",
"$",
"id",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"options",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"$",
"responseData",
"=",
"$",
"response",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"responseData",
"[",
"'result'",
"]",
")",
"&&",
"'not_found'",
"==",
"$",
"responseData",
"[",
"'result'",
"]",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"'Doc id '",
".",
"$",
"id",
".",
"' not found and can not be deleted'",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Deletes an entry by its unique identifier.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
@param int|string $id Document id
@param array $options
@throws \InvalidArgumentException
@throws \Elastica\Exception\NotFoundException
@return \Elastica\Response Response object
|
[
"Deletes",
"an",
"entry",
"by",
"its",
"unique",
"identifier",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L444-L463
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.deleteIds
|
public function deleteIds(array $ids, $routing = false)
{
return $this->getIndex()->getClient()->deleteIds($ids, $this->getIndex(), $this, $routing);
}
|
php
|
public function deleteIds(array $ids, $routing = false)
{
return $this->getIndex()->getClient()->deleteIds($ids, $this->getIndex(), $this, $routing);
}
|
[
"public",
"function",
"deleteIds",
"(",
"array",
"$",
"ids",
",",
"$",
"routing",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"getClient",
"(",
")",
"->",
"deleteIds",
"(",
"$",
"ids",
",",
"$",
"this",
"->",
"getIndex",
"(",
")",
",",
"$",
"this",
",",
"$",
"routing",
")",
";",
"}"
] |
Deletes the given list of ids from this type.
@param array $ids
@param string|bool $routing Optional routing key for all ids
@return \Elastica\Response Response object
|
[
"Deletes",
"the",
"given",
"list",
"of",
"ids",
"from",
"this",
"type",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L473-L476
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.deleteByQuery
|
public function deleteByQuery($query, array $options = [])
{
$query = Query::create($query);
$endpoint = new DeleteByQuery();
$endpoint->setBody($query->toArray());
$endpoint->setParams($options);
return $this->requestEndpoint($endpoint);
}
|
php
|
public function deleteByQuery($query, array $options = [])
{
$query = Query::create($query);
$endpoint = new DeleteByQuery();
$endpoint->setBody($query->toArray());
$endpoint->setParams($options);
return $this->requestEndpoint($endpoint);
}
|
[
"public",
"function",
"deleteByQuery",
"(",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"Query",
"::",
"create",
"(",
"$",
"query",
")",
";",
"$",
"endpoint",
"=",
"new",
"DeleteByQuery",
"(",
")",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"query",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] |
Deletes entries in the db based on a query.
@param \Elastica\Query|\Elastica\Query\AbstractQuery|string|array $query Query object
@param array $options Optional params
@return \Elastica\Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
|
[
"Deletes",
"entries",
"in",
"the",
"db",
"based",
"on",
"a",
"query",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L488-L497
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.request
|
public function request($path, $method, $data = [], array $query = [])
{
$path = $this->getName().'/'.$path;
return $this->getIndex()->request($path, $method, $data, $query);
}
|
php
|
public function request($path, $method, $data = [], array $query = [])
{
$path = $this->getName().'/'.$path;
return $this->getIndex()->request($path, $method, $data, $query);
}
|
[
"public",
"function",
"request",
"(",
"$",
"path",
",",
"$",
"method",
",",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"query",
"=",
"[",
"]",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'/'",
".",
"$",
"path",
";",
"return",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"request",
"(",
"$",
"path",
",",
"$",
"method",
",",
"$",
"data",
",",
"$",
"query",
")",
";",
"}"
] |
Makes calls to the elasticsearch server based on this type.
@param string $path Path to call
@param string $method Rest method to use (GET, POST, DELETE, PUT)
@param array $data OPTIONAL Arguments as array
@param array $query OPTIONAL Query params
@return \Elastica\Response Response object
|
[
"Makes",
"calls",
"to",
"the",
"elasticsearch",
"server",
"based",
"on",
"this",
"type",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L509-L514
|
train
|
ruflin/Elastica
|
lib/Elastica/Type.php
|
Type.requestEndpoint
|
public function requestEndpoint(AbstractEndpoint $endpoint)
{
$cloned = clone $endpoint;
$cloned->setType($this->getName());
return $this->getIndex()->requestEndpoint($cloned);
}
|
php
|
public function requestEndpoint(AbstractEndpoint $endpoint)
{
$cloned = clone $endpoint;
$cloned->setType($this->getName());
return $this->getIndex()->requestEndpoint($cloned);
}
|
[
"public",
"function",
"requestEndpoint",
"(",
"AbstractEndpoint",
"$",
"endpoint",
")",
"{",
"$",
"cloned",
"=",
"clone",
"$",
"endpoint",
";",
"$",
"cloned",
"->",
"setType",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"requestEndpoint",
"(",
"$",
"cloned",
")",
";",
"}"
] |
Makes calls to the elasticsearch server with usage official client Endpoint based on this type.
@param AbstractEndpoint $endpoint
@return Response
|
[
"Makes",
"calls",
"to",
"the",
"elasticsearch",
"server",
"with",
"usage",
"official",
"client",
"Endpoint",
"based",
"on",
"this",
"type",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Type.php#L523-L529
|
train
|
ruflin/Elastica
|
lib/Elastica/Index/Settings.php
|
Settings.get
|
public function get(string $setting = '')
{
$requestData = $this->request()->getData();
$data = \reset($requestData);
if (empty($data['settings']) || empty($data['settings']['index'])) {
// should not append, the request should throw a ResponseException
throw new NotFoundException('Index '.$this->getIndex()->getName().' not found');
}
$settings = $data['settings']['index'];
if (!$setting) {
// return all array
return $settings;
}
if (isset($settings[$setting])) {
return $settings[$setting];
}
if (false !== \strpos($setting, '.')) {
// translate old dot-notation settings to nested arrays
$keys = \explode('.', $setting);
foreach ($keys as $key) {
if (isset($settings[$key])) {
$settings = $settings[$key];
} else {
return null;
}
}
return $settings;
}
return null;
}
|
php
|
public function get(string $setting = '')
{
$requestData = $this->request()->getData();
$data = \reset($requestData);
if (empty($data['settings']) || empty($data['settings']['index'])) {
// should not append, the request should throw a ResponseException
throw new NotFoundException('Index '.$this->getIndex()->getName().' not found');
}
$settings = $data['settings']['index'];
if (!$setting) {
// return all array
return $settings;
}
if (isset($settings[$setting])) {
return $settings[$setting];
}
if (false !== \strpos($setting, '.')) {
// translate old dot-notation settings to nested arrays
$keys = \explode('.', $setting);
foreach ($keys as $key) {
if (isset($settings[$key])) {
$settings = $settings[$key];
} else {
return null;
}
}
return $settings;
}
return null;
}
|
[
"public",
"function",
"get",
"(",
"string",
"$",
"setting",
"=",
"''",
")",
"{",
"$",
"requestData",
"=",
"$",
"this",
"->",
"request",
"(",
")",
"->",
"getData",
"(",
")",
";",
"$",
"data",
"=",
"\\",
"reset",
"(",
"$",
"requestData",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'settings'",
"]",
")",
"||",
"empty",
"(",
"$",
"data",
"[",
"'settings'",
"]",
"[",
"'index'",
"]",
")",
")",
"{",
"// should not append, the request should throw a ResponseException",
"throw",
"new",
"NotFoundException",
"(",
"'Index '",
".",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"getName",
"(",
")",
".",
"' not found'",
")",
";",
"}",
"$",
"settings",
"=",
"$",
"data",
"[",
"'settings'",
"]",
"[",
"'index'",
"]",
";",
"if",
"(",
"!",
"$",
"setting",
")",
"{",
"// return all array",
"return",
"$",
"settings",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"settings",
"[",
"$",
"setting",
"]",
")",
")",
"{",
"return",
"$",
"settings",
"[",
"$",
"setting",
"]",
";",
"}",
"if",
"(",
"false",
"!==",
"\\",
"strpos",
"(",
"$",
"setting",
",",
"'.'",
")",
")",
"{",
"// translate old dot-notation settings to nested arrays",
"$",
"keys",
"=",
"\\",
"explode",
"(",
"'.'",
",",
"$",
"setting",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"settings",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"settings",
"=",
"$",
"settings",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"settings",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the current settings of the index.
If param is set, only specified setting is return.
'index.' is added in front of $setting.
@param string $setting OPTIONAL Setting name to return
@return array|string|null Settings data
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html
|
[
"Returns",
"the",
"current",
"settings",
"of",
"the",
"index",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index/Settings.php#L74-L109
|
train
|
ruflin/Elastica
|
lib/Elastica/Index/Settings.php
|
Settings.getBool
|
public function getBool(string $setting): bool
{
$data = $this->get($setting);
return 'true' === $data || '1' === $data || 'on' === $data || 'yes' === $data;
}
|
php
|
public function getBool(string $setting): bool
{
$data = $this->get($setting);
return 'true' === $data || '1' === $data || 'on' === $data || 'yes' === $data;
}
|
[
"public",
"function",
"getBool",
"(",
"string",
"$",
"setting",
")",
":",
"bool",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"setting",
")",
";",
"return",
"'true'",
"===",
"$",
"data",
"||",
"'1'",
"===",
"$",
"data",
"||",
"'on'",
"===",
"$",
"data",
"||",
"'yes'",
"===",
"$",
"data",
";",
"}"
] |
Returns a setting interpreted as a bool.
One can use a real bool, int(0), int(1) to set bool settings.
But Elasticsearch stores and returns all settings as strings and does
not normalize bool values. This method ensures a bool is returned for
whichever string representation is used like 'true', '1', 'on', 'yes'.
@param string $setting Setting name to return
@return bool
|
[
"Returns",
"a",
"setting",
"interpreted",
"as",
"a",
"bool",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index/Settings.php#L123-L128
|
train
|
ruflin/Elastica
|
lib/Elastica/Index/Settings.php
|
Settings.setMergePolicy
|
public function setMergePolicy(string $key, string $value): Response
{
$this->_index->close();
$response = $this->set(['merge.policy.'.$key => $value]);
$this->_index->open();
return $response;
}
|
php
|
public function setMergePolicy(string $key, string $value): Response
{
$this->_index->close();
$response = $this->set(['merge.policy.'.$key => $value]);
$this->_index->open();
return $response;
}
|
[
"public",
"function",
"setMergePolicy",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"value",
")",
":",
"Response",
"{",
"$",
"this",
"->",
"_index",
"->",
"close",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"set",
"(",
"[",
"'merge.policy.'",
".",
"$",
"key",
"=>",
"$",
"value",
"]",
")",
";",
"$",
"this",
"->",
"_index",
"->",
"open",
"(",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Sets the specific merge policies.
To have this changes made the index has to be closed and reopened
@param string $key Merge policy key (for ex. expunge_deletes_allowed)
@param string $value
@return Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-merge.html
|
[
"Sets",
"the",
"specific",
"merge",
"policies",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index/Settings.php#L291-L298
|
train
|
ruflin/Elastica
|
lib/Elastica/Index/Settings.php
|
Settings.request
|
public function request(array $data = [], string $method = Request::GET): Response
{
$path = '_settings';
if (!empty($data)) {
$data = ['index' => $data];
}
return $this->getIndex()->request($path, $method, $data);
}
|
php
|
public function request(array $data = [], string $method = Request::GET): Response
{
$path = '_settings';
if (!empty($data)) {
$data = ['index' => $data];
}
return $this->getIndex()->request($path, $method, $data);
}
|
[
"public",
"function",
"request",
"(",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"string",
"$",
"method",
"=",
"Request",
"::",
"GET",
")",
":",
"Response",
"{",
"$",
"path",
"=",
"'_settings'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"[",
"'index'",
"=>",
"$",
"data",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"request",
"(",
"$",
"path",
",",
"$",
"method",
",",
"$",
"data",
")",
";",
"}"
] |
Updates the given settings for the index.
With elasticsearch 0.16 the following settings are supported
- index.term_index_interval
- index.term_index_divisor
- index.translog.flush_threshold_ops
- index.translog.flush_threshold_size
- index.translog.flush_threshold_period
- index.refresh_interval
- index.merge.policy
- index.auto_expand_replicas
@param array $data OPTIONAL Data array
@param string $method OPTIONAL Transfer method (default = \Elastica\Request::GET)
@return Response Response object
|
[
"Updates",
"the",
"given",
"settings",
"for",
"the",
"index",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index/Settings.php#L356-L365
|
train
|
ruflin/Elastica
|
lib/Elastica/Cluster/Health.php
|
Health._retrieveHealthData
|
protected function _retrieveHealthData(): array
{
$endpoint = new \Elasticsearch\Endpoints\Cluster\Health();
$endpoint->setParams(['level' => 'shards']);
$response = $this->_client->requestEndpoint($endpoint);
return $response->getData();
}
|
php
|
protected function _retrieveHealthData(): array
{
$endpoint = new \Elasticsearch\Endpoints\Cluster\Health();
$endpoint->setParams(['level' => 'shards']);
$response = $this->_client->requestEndpoint($endpoint);
return $response->getData();
}
|
[
"protected",
"function",
"_retrieveHealthData",
"(",
")",
":",
"array",
"{",
"$",
"endpoint",
"=",
"new",
"\\",
"Elasticsearch",
"\\",
"Endpoints",
"\\",
"Cluster",
"\\",
"Health",
"(",
")",
";",
"$",
"endpoint",
"->",
"setParams",
"(",
"[",
"'level'",
"=>",
"'shards'",
"]",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"_client",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"return",
"$",
"response",
"->",
"getData",
"(",
")",
";",
"}"
] |
Retrieves the health data from the cluster.
@return array
|
[
"Retrieves",
"the",
"health",
"data",
"from",
"the",
"cluster",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Cluster/Health.php#L41-L49
|
train
|
ruflin/Elastica
|
lib/Elastica/Cluster/Health.php
|
Health.getIndices
|
public function getIndices(): array
{
$indices = [];
foreach ($this->_data['indices'] as $indexName => $index) {
$indices[$indexName] = new Index($indexName, $index);
}
return $indices;
}
|
php
|
public function getIndices(): array
{
$indices = [];
foreach ($this->_data['indices'] as $indexName => $index) {
$indices[$indexName] = new Index($indexName, $index);
}
return $indices;
}
|
[
"public",
"function",
"getIndices",
"(",
")",
":",
"array",
"{",
"$",
"indices",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"[",
"'indices'",
"]",
"as",
"$",
"indexName",
"=>",
"$",
"index",
")",
"{",
"$",
"indices",
"[",
"$",
"indexName",
"]",
"=",
"new",
"Index",
"(",
"$",
"indexName",
",",
"$",
"index",
")",
";",
"}",
"return",
"$",
"indices",
";",
"}"
] |
Gets the status of the indices.
@return Index[]
|
[
"Gets",
"the",
"status",
"of",
"the",
"indices",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Cluster/Health.php#L220-L228
|
train
|
ruflin/Elastica
|
lib/Elastica/Multi/ResultSet.php
|
ResultSet.hasError
|
public function hasError(): bool
{
foreach ($this->getResultSets() as $resultSet) {
if ($resultSet->getResponse()->hasError()) {
return true;
}
}
return false;
}
|
php
|
public function hasError(): bool
{
foreach ($this->getResultSets() as $resultSet) {
if ($resultSet->getResponse()->hasError()) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"hasError",
"(",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getResultSets",
"(",
")",
"as",
"$",
"resultSet",
")",
"{",
"if",
"(",
"$",
"resultSet",
"->",
"getResponse",
"(",
")",
"->",
"hasError",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
There is at least one result set with error.
@return bool
|
[
"There",
"is",
"at",
"least",
"one",
"result",
"set",
"with",
"error",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Multi/ResultSet.php#L72-L81
|
train
|
ruflin/Elastica
|
lib/Elastica/Suggest/AbstractSuggest.php
|
AbstractSuggest.setName
|
public function setName(string $name): AbstractSuggest
{
if (empty($name)) {
throw new InvalidException('Suggest name has to be set');
}
$this->_name = $name;
return $this;
}
|
php
|
public function setName(string $name): AbstractSuggest
{
if (empty($name)) {
throw new InvalidException('Suggest name has to be set');
}
$this->_name = $name;
return $this;
}
|
[
"public",
"function",
"setName",
"(",
"string",
"$",
"name",
")",
":",
"AbstractSuggest",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Suggest name has to be set'",
")",
";",
"}",
"$",
"this",
"->",
"_name",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the name of the suggest. It is automatically set by
the constructor.
@param string $name The name of the suggest
@throws InvalidException If name is empty
@return $this
|
[
"Sets",
"the",
"name",
"of",
"the",
"suggest",
".",
"It",
"is",
"automatically",
"set",
"by",
"the",
"constructor",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Suggest/AbstractSuggest.php#L118-L126
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Fuzzy.php
|
Fuzzy.setField
|
public function setField(string $fieldName, string $value): self
{
if (!\is_string($value) || !\is_string($fieldName)) {
throw new InvalidException('The field and value arguments must be of type string.');
}
if (\count($this->getParams()) > 0 && \key($this->getParams()) !== $fieldName) {
throw new InvalidException('Fuzzy query can only support a single field.');
}
return $this->setParam($fieldName, ['value' => $value]);
}
|
php
|
public function setField(string $fieldName, string $value): self
{
if (!\is_string($value) || !\is_string($fieldName)) {
throw new InvalidException('The field and value arguments must be of type string.');
}
if (\count($this->getParams()) > 0 && \key($this->getParams()) !== $fieldName) {
throw new InvalidException('Fuzzy query can only support a single field.');
}
return $this->setParam($fieldName, ['value' => $value]);
}
|
[
"public",
"function",
"setField",
"(",
"string",
"$",
"fieldName",
",",
"string",
"$",
"value",
")",
":",
"self",
"{",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"value",
")",
"||",
"!",
"\\",
"is_string",
"(",
"$",
"fieldName",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'The field and value arguments must be of type string.'",
")",
";",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
">",
"0",
"&&",
"\\",
"key",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
"!==",
"$",
"fieldName",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Fuzzy query can only support a single field.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setParam",
"(",
"$",
"fieldName",
",",
"[",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}"
] |
Set field for fuzzy query.
@param string $fieldName Field name
@param string $value String to search for
@return $this
|
[
"Set",
"field",
"for",
"fuzzy",
"query",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Fuzzy.php#L37-L47
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Fuzzy.php
|
Fuzzy.setFieldOption
|
public function setFieldOption(string $option, $value): self
{
//Retrieve the single existing field for alteration.
$params = $this->getParams();
if (\count($params) < 1) {
throw new InvalidException('No field has been set');
}
$key = \key($params);
$params[$key][$option] = $value;
return $this->setParam($key, $params[$key]);
}
|
php
|
public function setFieldOption(string $option, $value): self
{
//Retrieve the single existing field for alteration.
$params = $this->getParams();
if (\count($params) < 1) {
throw new InvalidException('No field has been set');
}
$key = \key($params);
$params[$key][$option] = $value;
return $this->setParam($key, $params[$key]);
}
|
[
"public",
"function",
"setFieldOption",
"(",
"string",
"$",
"option",
",",
"$",
"value",
")",
":",
"self",
"{",
"//Retrieve the single existing field for alteration.",
"$",
"params",
"=",
"$",
"this",
"->",
"getParams",
"(",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"params",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'No field has been set'",
")",
";",
"}",
"$",
"key",
"=",
"\\",
"key",
"(",
"$",
"params",
")",
";",
"$",
"params",
"[",
"$",
"key",
"]",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"setParam",
"(",
"$",
"key",
",",
"$",
"params",
"[",
"$",
"key",
"]",
")",
";",
"}"
] |
Set optional parameters on the existing query.
@param string $option option name
@param mixed $value Value of the parameter
@return $this
|
[
"Set",
"optional",
"parameters",
"on",
"the",
"existing",
"query",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Fuzzy.php#L57-L68
|
train
|
ruflin/Elastica
|
lib/Elastica/Result.php
|
Result.getData
|
public function getData()
{
if (isset($this->_hit['fields'])) {
return isset($this->_hit['_source'])
? \array_merge($this->getFields(), $this->getSource())
: $this->getFields();
}
return $this->getSource();
}
|
php
|
public function getData()
{
if (isset($this->_hit['fields'])) {
return isset($this->_hit['_source'])
? \array_merge($this->getFields(), $this->getSource())
: $this->getFields();
}
return $this->getSource();
}
|
[
"public",
"function",
"getData",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_hit",
"[",
"'fields'",
"]",
")",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_hit",
"[",
"'_source'",
"]",
")",
"?",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"getFields",
"(",
")",
",",
"$",
"this",
"->",
"getSource",
"(",
")",
")",
":",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getSource",
"(",
")",
";",
"}"
] |
Returns result data.
Checks for partial result data with getFields, falls back to getSource or both
@return array Result data array
|
[
"Returns",
"result",
"data",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Result.php#L170-L179
|
train
|
ruflin/Elastica
|
lib/Elastica/Result.php
|
Result.getDocument
|
public function getDocument()
{
$doc = new Document();
$doc->setData($this->getSource());
$hit = $this->getHit();
unset($hit['_source']);
unset($hit['_explanation']);
unset($hit['highlight']);
unset($hit['_score']);
$doc->setParams($hit);
return $doc;
}
|
php
|
public function getDocument()
{
$doc = new Document();
$doc->setData($this->getSource());
$hit = $this->getHit();
unset($hit['_source']);
unset($hit['_explanation']);
unset($hit['highlight']);
unset($hit['_score']);
$doc->setParams($hit);
return $doc;
}
|
[
"public",
"function",
"getDocument",
"(",
")",
"{",
"$",
"doc",
"=",
"new",
"Document",
"(",
")",
";",
"$",
"doc",
"->",
"setData",
"(",
"$",
"this",
"->",
"getSource",
"(",
")",
")",
";",
"$",
"hit",
"=",
"$",
"this",
"->",
"getHit",
"(",
")",
";",
"unset",
"(",
"$",
"hit",
"[",
"'_source'",
"]",
")",
";",
"unset",
"(",
"$",
"hit",
"[",
"'_explanation'",
"]",
")",
";",
"unset",
"(",
"$",
"hit",
"[",
"'highlight'",
"]",
")",
";",
"unset",
"(",
"$",
"hit",
"[",
"'_score'",
"]",
")",
";",
"$",
"doc",
"->",
"setParams",
"(",
"$",
"hit",
")",
";",
"return",
"$",
"doc",
";",
"}"
] |
Returns Document.
@return Document
|
[
"Returns",
"Document",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Result.php#L216-L228
|
train
|
ruflin/Elastica
|
lib/Elastica/Pipeline.php
|
Pipeline.create
|
public function create()
{
if (empty($this->id)) {
throw new InvalidException('You should set a valid pipeline id');
}
if (empty($this->_params['description'])) {
throw new InvalidException('You should set a valid processor description.');
}
if (empty($this->_processors['processors'])) {
throw new InvalidException('You should set a valid processor of type Elastica\Processor\AbstractProcessor.');
}
$endpoint = new Put();
$endpoint->setID($this->id);
$endpoint->setBody($this->toArray());
return $this->requestEndpoint($endpoint);
}
|
php
|
public function create()
{
if (empty($this->id)) {
throw new InvalidException('You should set a valid pipeline id');
}
if (empty($this->_params['description'])) {
throw new InvalidException('You should set a valid processor description.');
}
if (empty($this->_processors['processors'])) {
throw new InvalidException('You should set a valid processor of type Elastica\Processor\AbstractProcessor.');
}
$endpoint = new Put();
$endpoint->setID($this->id);
$endpoint->setBody($this->toArray());
return $this->requestEndpoint($endpoint);
}
|
[
"public",
"function",
"create",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"id",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'You should set a valid pipeline id'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_params",
"[",
"'description'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'You should set a valid processor description.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_processors",
"[",
"'processors'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'You should set a valid processor of type Elastica\\Processor\\AbstractProcessor.'",
")",
";",
"}",
"$",
"endpoint",
"=",
"new",
"Put",
"(",
")",
";",
"$",
"endpoint",
"->",
"setID",
"(",
"$",
"this",
"->",
"id",
")",
";",
"$",
"endpoint",
"->",
"setBody",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] |
Create a Pipeline.
@return Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-pipeline-api.html
|
[
"Create",
"a",
"Pipeline",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Pipeline.php#L60-L79
|
train
|
ruflin/Elastica
|
lib/Elastica/Pipeline.php
|
Pipeline.getPipeline
|
public function getPipeline(string $id)
{
$endpoint = new Get();
$endpoint->setID($id);
return $this->requestEndpoint($endpoint);
}
|
php
|
public function getPipeline(string $id)
{
$endpoint = new Get();
$endpoint->setID($id);
return $this->requestEndpoint($endpoint);
}
|
[
"public",
"function",
"getPipeline",
"(",
"string",
"$",
"id",
")",
"{",
"$",
"endpoint",
"=",
"new",
"Get",
"(",
")",
";",
"$",
"endpoint",
"->",
"setID",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] |
Get a Pipeline Object.
@param string $id Pipeline name
@return Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-pipeline-api.html
|
[
"Get",
"a",
"Pipeline",
"Object",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Pipeline.php#L90-L96
|
train
|
ruflin/Elastica
|
lib/Elastica/Pipeline.php
|
Pipeline.deletePipeline
|
public function deletePipeline(string $id)
{
$endpoint = new Delete();
$endpoint->setID($id);
return $this->requestEndpoint($endpoint);
}
|
php
|
public function deletePipeline(string $id)
{
$endpoint = new Delete();
$endpoint->setID($id);
return $this->requestEndpoint($endpoint);
}
|
[
"public",
"function",
"deletePipeline",
"(",
"string",
"$",
"id",
")",
"{",
"$",
"endpoint",
"=",
"new",
"Delete",
"(",
")",
";",
"$",
"endpoint",
"->",
"setID",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"requestEndpoint",
"(",
"$",
"endpoint",
")",
";",
"}"
] |
Delete a Pipeline.
@param string $id Pipeline name
@return Response
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-pipeline-api.html
|
[
"Delete",
"a",
"Pipeline",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Pipeline.php#L107-L113
|
train
|
ruflin/Elastica
|
lib/Elastica/Pipeline.php
|
Pipeline.addProcessor
|
public function addProcessor(AbstractProcessor $processor)
{
if (empty($this->_processors)) {
$this->_processors['processors'] = $processor->toArray();
$this->_params['processors'] = [];
} else {
$this->_processors['processors'] = \array_merge($this->_processors['processors'], $processor->toArray());
}
return $this;
}
|
php
|
public function addProcessor(AbstractProcessor $processor)
{
if (empty($this->_processors)) {
$this->_processors['processors'] = $processor->toArray();
$this->_params['processors'] = [];
} else {
$this->_processors['processors'] = \array_merge($this->_processors['processors'], $processor->toArray());
}
return $this;
}
|
[
"public",
"function",
"addProcessor",
"(",
"AbstractProcessor",
"$",
"processor",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_processors",
")",
")",
"{",
"$",
"this",
"->",
"_processors",
"[",
"'processors'",
"]",
"=",
"$",
"processor",
"->",
"toArray",
"(",
")",
";",
"$",
"this",
"->",
"_params",
"[",
"'processors'",
"]",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_processors",
"[",
"'processors'",
"]",
"=",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"_processors",
"[",
"'processors'",
"]",
",",
"$",
"processor",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add a processor.
@param AbstractProcessor $processor
@return $this
|
[
"Add",
"a",
"processor",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Pipeline.php#L144-L154
|
train
|
ruflin/Elastica
|
lib/Elastica/Exception/Bulk/ResponseException.php
|
ResponseException.getFailures
|
public function getFailures(): array
{
$errors = [];
foreach ($this->getActionExceptions() as $actionException) {
$errors[] = $actionException->getMessage();
}
return $errors;
}
|
php
|
public function getFailures(): array
{
$errors = [];
foreach ($this->getActionExceptions() as $actionException) {
$errors[] = $actionException->getMessage();
}
return $errors;
}
|
[
"public",
"function",
"getFailures",
"(",
")",
":",
"array",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getActionExceptions",
"(",
")",
"as",
"$",
"actionException",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"$",
"actionException",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Returns array of failed actions.
@return string[] Array of failed actions
|
[
"Returns",
"array",
"of",
"failed",
"actions",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Exception/Bulk/ResponseException.php#L68-L77
|
train
|
ruflin/Elastica
|
lib/Elastica/Aggregation/DateHistogram.php
|
DateHistogram.setExtendedBounds
|
public function setExtendedBounds(string $min = '', string $max = ''): self
{
$bounds = [];
$bounds['min'] = $min;
$bounds['max'] = $max;
// switch if min is higher then max
if (\strtotime($min) > \strtotime($max)) {
$bounds['min'] = $max;
$bounds['max'] = $min;
}
return $this->setParam('extended_bounds', $bounds);
}
|
php
|
public function setExtendedBounds(string $min = '', string $max = ''): self
{
$bounds = [];
$bounds['min'] = $min;
$bounds['max'] = $max;
// switch if min is higher then max
if (\strtotime($min) > \strtotime($max)) {
$bounds['min'] = $max;
$bounds['max'] = $min;
}
return $this->setParam('extended_bounds', $bounds);
}
|
[
"public",
"function",
"setExtendedBounds",
"(",
"string",
"$",
"min",
"=",
"''",
",",
"string",
"$",
"max",
"=",
"''",
")",
":",
"self",
"{",
"$",
"bounds",
"=",
"[",
"]",
";",
"$",
"bounds",
"[",
"'min'",
"]",
"=",
"$",
"min",
";",
"$",
"bounds",
"[",
"'max'",
"]",
"=",
"$",
"max",
";",
"// switch if min is higher then max",
"if",
"(",
"\\",
"strtotime",
"(",
"$",
"min",
")",
">",
"\\",
"strtotime",
"(",
"$",
"max",
")",
")",
"{",
"$",
"bounds",
"[",
"'min'",
"]",
"=",
"$",
"max",
";",
"$",
"bounds",
"[",
"'max'",
"]",
"=",
"$",
"min",
";",
"}",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'extended_bounds'",
",",
"$",
"bounds",
")",
";",
"}"
] |
Set extended bounds option.
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html#search-aggregations-bucket-histogram-aggregation-extended-bounds
@param string $min see link for formatting options
@param string $max see link for formatting options
@return $this
|
[
"Set",
"extended",
"bounds",
"option",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Aggregation/DateHistogram.php#L74-L86
|
train
|
ruflin/Elastica
|
lib/Elastica/Document.php
|
Document.addFile
|
public function addFile($key, $filepath, $mimeType = '')
{
$value = \base64_encode(\file_get_contents($filepath));
if (!empty($mimeType)) {
$value = ['_content_type' => $mimeType, '_name' => $filepath, '_content' => $value];
}
$this->set($key, $value);
return $this;
}
|
php
|
public function addFile($key, $filepath, $mimeType = '')
{
$value = \base64_encode(\file_get_contents($filepath));
if (!empty($mimeType)) {
$value = ['_content_type' => $mimeType, '_name' => $filepath, '_content' => $value];
}
$this->set($key, $value);
return $this;
}
|
[
"public",
"function",
"addFile",
"(",
"$",
"key",
",",
"$",
"filepath",
",",
"$",
"mimeType",
"=",
"''",
")",
"{",
"$",
"value",
"=",
"\\",
"base64_encode",
"(",
"\\",
"file_get_contents",
"(",
"$",
"filepath",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"mimeType",
")",
")",
"{",
"$",
"value",
"=",
"[",
"'_content_type'",
"=>",
"$",
"mimeType",
",",
"'_name'",
"=>",
"$",
"filepath",
",",
"'_content'",
"=>",
"$",
"value",
"]",
";",
"}",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a file to the index.
To use this feature you have to call the following command in the
elasticsearch directory:
<code>
./bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/1.6.0
</code>
This installs the tika file analysis plugin. More infos about supported formats
can be found here: {@link http://tika.apache.org/0.7/formats.html}
@param string $key Key to add the file to
@param string $filepath Path to add the file
@param string $mimeType OPTIONAL Header mime type
@return $this
|
[
"Adds",
"a",
"file",
"to",
"the",
"index",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Document.php#L167-L178
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Wildcard.php
|
Wildcard.setValue
|
public function setValue(string $key, string $value, float $boost = 1.0): self
{
return $this->setParam($key, ['value' => $value, 'boost' => $boost]);
}
|
php
|
public function setValue(string $key, string $value, float $boost = 1.0): self
{
return $this->setParam($key, ['value' => $value, 'boost' => $boost]);
}
|
[
"public",
"function",
"setValue",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"value",
",",
"float",
"$",
"boost",
"=",
"1.0",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setParam",
"(",
"$",
"key",
",",
"[",
"'value'",
"=>",
"$",
"value",
",",
"'boost'",
"=>",
"$",
"boost",
"]",
")",
";",
"}"
] |
Sets the query expression for a key with its boost value.
@param string $key
@param string $value
@param float $boost
@return $this
|
[
"Sets",
"the",
"query",
"expression",
"for",
"a",
"key",
"with",
"its",
"boost",
"value",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Wildcard.php#L37-L40
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/SpanFirst.php
|
SpanFirst._setQuery
|
protected function _setQuery(string $type, $args): self
{
if (!\is_array($args) && !($args instanceof AbstractSpanQuery)) {
throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractSpanQuery');
}
return $this->setParam($type, $args);
}
|
php
|
protected function _setQuery(string $type, $args): self
{
if (!\is_array($args) && !($args instanceof AbstractSpanQuery)) {
throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractSpanQuery');
}
return $this->setParam($type, $args);
}
|
[
"protected",
"function",
"_setQuery",
"(",
"string",
"$",
"type",
",",
"$",
"args",
")",
":",
"self",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"args",
")",
"&&",
"!",
"(",
"$",
"args",
"instanceof",
"AbstractSpanQuery",
")",
")",
"{",
"throw",
"new",
"InvalidException",
"(",
"'Invalid parameter. Has to be array or instance of Elastica\\Query\\AbstractSpanQuery'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setParam",
"(",
"$",
"type",
",",
"$",
"args",
")",
";",
"}"
] |
Sets a query to the current object.
@param string $type Query type
@param AbstractQuery|array $args Query
@throws InvalidException If not valid query
@return $this
|
[
"Sets",
"a",
"query",
"to",
"the",
"current",
"object",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/SpanFirst.php#L71-L78
|
train
|
ruflin/Elastica
|
lib/Elastica/Query.php
|
Query.create
|
public static function create($query)
{
switch (true) {
case $query instanceof self:
return $query;
case $query instanceof AbstractQuery:
return new self($query);
case empty($query):
return new self(new MatchAll());
case \is_array($query):
return new self($query);
case \is_string($query):
return new self(new QueryString($query));
case $query instanceof AbstractSuggest:
return new self(new Suggest($query));
case $query instanceof Suggest:
return new self($query);
}
throw new InvalidException('Unexpected argument to create a query for.');
}
|
php
|
public static function create($query)
{
switch (true) {
case $query instanceof self:
return $query;
case $query instanceof AbstractQuery:
return new self($query);
case empty($query):
return new self(new MatchAll());
case \is_array($query):
return new self($query);
case \is_string($query):
return new self(new QueryString($query));
case $query instanceof AbstractSuggest:
return new self(new Suggest($query));
case $query instanceof Suggest:
return new self($query);
}
throw new InvalidException('Unexpected argument to create a query for.');
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"query",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"query",
"instanceof",
"self",
":",
"return",
"$",
"query",
";",
"case",
"$",
"query",
"instanceof",
"AbstractQuery",
":",
"return",
"new",
"self",
"(",
"$",
"query",
")",
";",
"case",
"empty",
"(",
"$",
"query",
")",
":",
"return",
"new",
"self",
"(",
"new",
"MatchAll",
"(",
")",
")",
";",
"case",
"\\",
"is_array",
"(",
"$",
"query",
")",
":",
"return",
"new",
"self",
"(",
"$",
"query",
")",
";",
"case",
"\\",
"is_string",
"(",
"$",
"query",
")",
":",
"return",
"new",
"self",
"(",
"new",
"QueryString",
"(",
"$",
"query",
")",
")",
";",
"case",
"$",
"query",
"instanceof",
"AbstractSuggest",
":",
"return",
"new",
"self",
"(",
"new",
"Suggest",
"(",
"$",
"query",
")",
")",
";",
"case",
"$",
"query",
"instanceof",
"Suggest",
":",
"return",
"new",
"self",
"(",
"$",
"query",
")",
";",
"}",
"throw",
"new",
"InvalidException",
"(",
"'Unexpected argument to create a query for.'",
")",
";",
"}"
] |
Transforms the argument to a query object.
For example, an empty argument will return a \Elastica\Query with a \Elastica\Query\MatchAll.
@param mixed $query
@throws InvalidException For an invalid argument
@return self
|
[
"Transforms",
"the",
"argument",
"to",
"a",
"query",
"object",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query.php#L59-L80
|
train
|
ruflin/Elastica
|
lib/Elastica/Query.php
|
Query.setScriptFields
|
public function setScriptFields($scriptFields)
{
if (\is_array($scriptFields)) {
$scriptFields = new ScriptFields($scriptFields);
}
return $this->setParam('script_fields', $scriptFields);
}
|
php
|
public function setScriptFields($scriptFields)
{
if (\is_array($scriptFields)) {
$scriptFields = new ScriptFields($scriptFields);
}
return $this->setParam('script_fields', $scriptFields);
}
|
[
"public",
"function",
"setScriptFields",
"(",
"$",
"scriptFields",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"scriptFields",
")",
")",
"{",
"$",
"scriptFields",
"=",
"new",
"ScriptFields",
"(",
"$",
"scriptFields",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'script_fields'",
",",
"$",
"scriptFields",
")",
";",
"}"
] |
Set script fields.
@param array|\Elastica\Script\ScriptFields $scriptFields Script fields
@return $this
@see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html
|
[
"Set",
"script",
"fields",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query.php#L280-L287
|
train
|
ruflin/Elastica
|
lib/Elastica/Query.php
|
Query.addScriptField
|
public function addScriptField($name, AbstractScript $script)
{
if (isset($this->_params['script_fields'])) {
$this->_params['script_fields']->addScript($name, $script);
} else {
$this->setScriptFields([$name => $script]);
}
return $this;
}
|
php
|
public function addScriptField($name, AbstractScript $script)
{
if (isset($this->_params['script_fields'])) {
$this->_params['script_fields']->addScript($name, $script);
} else {
$this->setScriptFields([$name => $script]);
}
return $this;
}
|
[
"public",
"function",
"addScriptField",
"(",
"$",
"name",
",",
"AbstractScript",
"$",
"script",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_params",
"[",
"'script_fields'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_params",
"[",
"'script_fields'",
"]",
"->",
"addScript",
"(",
"$",
"name",
",",
"$",
"script",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setScriptFields",
"(",
"[",
"$",
"name",
"=>",
"$",
"script",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Adds a Script to the query.
@param string $name
@param \Elastica\Script\AbstractScript $script Script object
@return $this
|
[
"Adds",
"a",
"Script",
"to",
"the",
"query",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query.php#L297-L306
|
train
|
ruflin/Elastica
|
lib/Elastica/Query.php
|
Query.toArray
|
public function toArray()
{
if (!isset($this->_params['query']) && (0 == $this->_suggest)) {
$this->setQuery(new MatchAll());
}
if (isset($this->_params['post_filter']) && 0 === \count(($this->_params['post_filter'])->toArray())) {
unset($this->_params['post_filter']);
}
$array = $this->_convertArrayable($this->_params);
if (isset($array['suggest'])) {
$array['suggest'] = $array['suggest']['suggest'];
}
return $array;
}
|
php
|
public function toArray()
{
if (!isset($this->_params['query']) && (0 == $this->_suggest)) {
$this->setQuery(new MatchAll());
}
if (isset($this->_params['post_filter']) && 0 === \count(($this->_params['post_filter'])->toArray())) {
unset($this->_params['post_filter']);
}
$array = $this->_convertArrayable($this->_params);
if (isset($array['suggest'])) {
$array['suggest'] = $array['suggest']['suggest'];
}
return $array;
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_params",
"[",
"'query'",
"]",
")",
"&&",
"(",
"0",
"==",
"$",
"this",
"->",
"_suggest",
")",
")",
"{",
"$",
"this",
"->",
"setQuery",
"(",
"new",
"MatchAll",
"(",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_params",
"[",
"'post_filter'",
"]",
")",
"&&",
"0",
"===",
"\\",
"count",
"(",
"(",
"$",
"this",
"->",
"_params",
"[",
"'post_filter'",
"]",
")",
"->",
"toArray",
"(",
")",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_params",
"[",
"'post_filter'",
"]",
")",
";",
"}",
"$",
"array",
"=",
"$",
"this",
"->",
"_convertArrayable",
"(",
"$",
"this",
"->",
"_params",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"'suggest'",
"]",
")",
")",
"{",
"$",
"array",
"[",
"'suggest'",
"]",
"=",
"$",
"array",
"[",
"'suggest'",
"]",
"[",
"'suggest'",
"]",
";",
"}",
"return",
"$",
"array",
";",
"}"
] |
Converts all query params to an array.
@return array Query array
|
[
"Converts",
"all",
"query",
"params",
"to",
"an",
"array",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query.php#L327-L344
|
train
|
ruflin/Elastica
|
lib/Elastica/Query.php
|
Query.setRescore
|
public function setRescore($rescore)
{
if (\is_array($rescore)) {
$buffer = [];
foreach ($rescore as $rescoreQuery) {
$buffer[] = $rescoreQuery;
}
} else {
$buffer = $rescore;
}
return $this->setParam('rescore', $buffer);
}
|
php
|
public function setRescore($rescore)
{
if (\is_array($rescore)) {
$buffer = [];
foreach ($rescore as $rescoreQuery) {
$buffer[] = $rescoreQuery;
}
} else {
$buffer = $rescore;
}
return $this->setParam('rescore', $buffer);
}
|
[
"public",
"function",
"setRescore",
"(",
"$",
"rescore",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"rescore",
")",
")",
"{",
"$",
"buffer",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rescore",
"as",
"$",
"rescoreQuery",
")",
"{",
"$",
"buffer",
"[",
"]",
"=",
"$",
"rescoreQuery",
";",
"}",
"}",
"else",
"{",
"$",
"buffer",
"=",
"$",
"rescore",
";",
"}",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'rescore'",
",",
"$",
"buffer",
")",
";",
"}"
] |
Add a Rescore.
@param mixed $rescore suggestion object
@return $this
|
[
"Add",
"a",
"Rescore",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query.php#L387-L400
|
train
|
ruflin/Elastica
|
lib/Elastica/Index/Stats.php
|
Stats.refresh
|
public function refresh()
{
$this->_response = $this->getIndex()->requestEndpoint(new \Elasticsearch\Endpoints\Indices\Stats());
$this->_data = $this->getResponse()->getData();
}
|
php
|
public function refresh()
{
$this->_response = $this->getIndex()->requestEndpoint(new \Elasticsearch\Endpoints\Indices\Stats());
$this->_data = $this->getResponse()->getData();
}
|
[
"public",
"function",
"refresh",
"(",
")",
"{",
"$",
"this",
"->",
"_response",
"=",
"$",
"this",
"->",
"getIndex",
"(",
")",
"->",
"requestEndpoint",
"(",
"new",
"\\",
"Elasticsearch",
"\\",
"Endpoints",
"\\",
"Indices",
"\\",
"Stats",
"(",
")",
")",
";",
"$",
"this",
"->",
"_data",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getData",
"(",
")",
";",
"}"
] |
Reloads all status data of this object.
|
[
"Reloads",
"all",
"status",
"data",
"of",
"this",
"object",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Index/Stats.php#L103-L107
|
train
|
ruflin/Elastica
|
lib/Elastica/Rescore/Query.php
|
Query.setRescoreQuery
|
public function setRescoreQuery($rescoreQuery): Query
{
$rescoreQuery = BaseQuery::create($rescoreQuery);
$query = $this->getParam('query');
$query['rescore_query'] = $rescoreQuery;
return $this->setParam('query', $query);
}
|
php
|
public function setRescoreQuery($rescoreQuery): Query
{
$rescoreQuery = BaseQuery::create($rescoreQuery);
$query = $this->getParam('query');
$query['rescore_query'] = $rescoreQuery;
return $this->setParam('query', $query);
}
|
[
"public",
"function",
"setRescoreQuery",
"(",
"$",
"rescoreQuery",
")",
":",
"Query",
"{",
"$",
"rescoreQuery",
"=",
"BaseQuery",
"::",
"create",
"(",
"$",
"rescoreQuery",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'query'",
")",
";",
"$",
"query",
"[",
"'rescore_query'",
"]",
"=",
"$",
"rescoreQuery",
";",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'query'",
",",
"$",
"query",
")",
";",
"}"
] |
Sets rescoreQuery object.
@param string|\Elastica\Query|\Elastica\Query\AbstractQuery $rescoreQuery
@return $this
|
[
"Sets",
"rescoreQuery",
"object",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Rescore/Query.php#L57-L65
|
train
|
ruflin/Elastica
|
lib/Elastica/Rescore/Query.php
|
Query.setQueryWeight
|
public function setQueryWeight(float $weight): Query
{
$query = $this->getParam('query');
$query['query_weight'] = $weight;
return $this->setParam('query', $query);
}
|
php
|
public function setQueryWeight(float $weight): Query
{
$query = $this->getParam('query');
$query['query_weight'] = $weight;
return $this->setParam('query', $query);
}
|
[
"public",
"function",
"setQueryWeight",
"(",
"float",
"$",
"weight",
")",
":",
"Query",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'query'",
")",
";",
"$",
"query",
"[",
"'query_weight'",
"]",
"=",
"$",
"weight",
";",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'query'",
",",
"$",
"query",
")",
";",
"}"
] |
Sets query_weight.
@param float $weight
@return $this
|
[
"Sets",
"query_weight",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Rescore/Query.php#L74-L80
|
train
|
ruflin/Elastica
|
lib/Elastica/Rescore/Query.php
|
Query.setRescoreQueryWeight
|
public function setRescoreQueryWeight(float $weight): Query
{
$query = $this->getParam('query');
$query['rescore_query_weight'] = $weight;
return $this->setParam('query', $query);
}
|
php
|
public function setRescoreQueryWeight(float $weight): Query
{
$query = $this->getParam('query');
$query['rescore_query_weight'] = $weight;
return $this->setParam('query', $query);
}
|
[
"public",
"function",
"setRescoreQueryWeight",
"(",
"float",
"$",
"weight",
")",
":",
"Query",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'query'",
")",
";",
"$",
"query",
"[",
"'rescore_query_weight'",
"]",
"=",
"$",
"weight",
";",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'query'",
",",
"$",
"query",
")",
";",
"}"
] |
Sets rescore_query_weight.
@param float $weight
@return $this
|
[
"Sets",
"rescore_query_weight",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Rescore/Query.php#L89-L95
|
train
|
ruflin/Elastica
|
lib/Elastica/Util.php
|
Util.escapeDateMath
|
public static function escapeDateMath($requestUri)
{
if (empty($requestUri)) {
return $requestUri;
}
// Check if date math if used at all. Find last '>'. E.g. /<log-{now/d}>,log-2011.12.01/log/_refresh
$pos1 = \strrpos($requestUri, '>');
if (false === $pos1) {
return $requestUri;
}
// Find the position up to which we should escape.
// Should be next slash '/' after last '>' E.g. /<log-{now/d}>,log-2011.12.01/log/_refresh
$pos2 = \strpos($requestUri, '/', $pos1);
$pos2 = false !== $pos2 ? $pos2 : \strlen($requestUri);
// Cut out the bit we need to escape: /<log-{now/d}>,log-2011.12.01
$uriSegment = \substr($requestUri, 0, $pos2);
// Escape using character map
$escapedUriSegment = \str_replace(static::$dateMathSymbols, static::$escapedDateMathSymbols, $uriSegment);
// '\\{' and '\\}' should not be escaped
if (false !== \strpos($uriSegment, '\\\\')) {
$escapedUriSegment = \str_replace(['\\\\%7B', '\\\\%7D'], ['\\\\{', '\\\\}'], $escapedUriSegment);
}
// Replace part of the string. E.g. /%3Clog-%7Bnow%2Fd%7D%3E%2Clog-2011.12.01/log/_refresh
return \substr_replace($requestUri, $escapedUriSegment, 0, $pos2);
}
|
php
|
public static function escapeDateMath($requestUri)
{
if (empty($requestUri)) {
return $requestUri;
}
// Check if date math if used at all. Find last '>'. E.g. /<log-{now/d}>,log-2011.12.01/log/_refresh
$pos1 = \strrpos($requestUri, '>');
if (false === $pos1) {
return $requestUri;
}
// Find the position up to which we should escape.
// Should be next slash '/' after last '>' E.g. /<log-{now/d}>,log-2011.12.01/log/_refresh
$pos2 = \strpos($requestUri, '/', $pos1);
$pos2 = false !== $pos2 ? $pos2 : \strlen($requestUri);
// Cut out the bit we need to escape: /<log-{now/d}>,log-2011.12.01
$uriSegment = \substr($requestUri, 0, $pos2);
// Escape using character map
$escapedUriSegment = \str_replace(static::$dateMathSymbols, static::$escapedDateMathSymbols, $uriSegment);
// '\\{' and '\\}' should not be escaped
if (false !== \strpos($uriSegment, '\\\\')) {
$escapedUriSegment = \str_replace(['\\\\%7B', '\\\\%7D'], ['\\\\{', '\\\\}'], $escapedUriSegment);
}
// Replace part of the string. E.g. /%3Clog-%7Bnow%2Fd%7D%3E%2Clog-2011.12.01/log/_refresh
return \substr_replace($requestUri, $escapedUriSegment, 0, $pos2);
}
|
[
"public",
"static",
"function",
"escapeDateMath",
"(",
"$",
"requestUri",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"requestUri",
")",
")",
"{",
"return",
"$",
"requestUri",
";",
"}",
"// Check if date math if used at all. Find last '>'. E.g. /<log-{now/d}>,log-2011.12.01/log/_refresh",
"$",
"pos1",
"=",
"\\",
"strrpos",
"(",
"$",
"requestUri",
",",
"'>'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"pos1",
")",
"{",
"return",
"$",
"requestUri",
";",
"}",
"// Find the position up to which we should escape.",
"// Should be next slash '/' after last '>' E.g. /<log-{now/d}>,log-2011.12.01/log/_refresh",
"$",
"pos2",
"=",
"\\",
"strpos",
"(",
"$",
"requestUri",
",",
"'/'",
",",
"$",
"pos1",
")",
";",
"$",
"pos2",
"=",
"false",
"!==",
"$",
"pos2",
"?",
"$",
"pos2",
":",
"\\",
"strlen",
"(",
"$",
"requestUri",
")",
";",
"// Cut out the bit we need to escape: /<log-{now/d}>,log-2011.12.01",
"$",
"uriSegment",
"=",
"\\",
"substr",
"(",
"$",
"requestUri",
",",
"0",
",",
"$",
"pos2",
")",
";",
"// Escape using character map",
"$",
"escapedUriSegment",
"=",
"\\",
"str_replace",
"(",
"static",
"::",
"$",
"dateMathSymbols",
",",
"static",
"::",
"$",
"escapedDateMathSymbols",
",",
"$",
"uriSegment",
")",
";",
"// '\\\\{' and '\\\\}' should not be escaped",
"if",
"(",
"false",
"!==",
"\\",
"strpos",
"(",
"$",
"uriSegment",
",",
"'\\\\\\\\'",
")",
")",
"{",
"$",
"escapedUriSegment",
"=",
"\\",
"str_replace",
"(",
"[",
"'\\\\\\\\%7B'",
",",
"'\\\\\\\\%7D'",
"]",
",",
"[",
"'\\\\\\\\{'",
",",
"'\\\\\\\\}'",
"]",
",",
"$",
"escapedUriSegment",
")",
";",
"}",
"// Replace part of the string. E.g. /%3Clog-%7Bnow%2Fd%7D%3E%2Clog-2011.12.01/log/_refresh",
"return",
"\\",
"substr_replace",
"(",
"$",
"requestUri",
",",
"$",
"escapedUriSegment",
",",
"0",
",",
"$",
"pos2",
")",
";",
"}"
] |
Escapes date math symbols within request URI.
@see https://www.elastic.co/guide/en/elasticsearch/reference/5.x/date-math-index-names.html
@param string $requestUri
@return string
|
[
"Escapes",
"date",
"math",
"symbols",
"within",
"request",
"URI",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Util.php#L43-L73
|
train
|
ruflin/Elastica
|
lib/Elastica/Util.php
|
Util.convertRequestToCurlCommand
|
public static function convertRequestToCurlCommand(Request $request)
{
$message = 'curl -X'.\strtoupper($request->getMethod()).' ';
$message .= '\'http://'.$request->getConnection()->getHost().':'.$request->getConnection()->getPort().'/';
$message .= $request->getPath();
$query = $request->getQuery();
if (!empty($query)) {
$message .= '?'.\http_build_query($query);
}
$message .= '\'';
$data = $request->getData();
if (!empty($data)) {
$message .= ' -d \''.JSON::stringify($data).'\'';
}
return $message;
}
|
php
|
public static function convertRequestToCurlCommand(Request $request)
{
$message = 'curl -X'.\strtoupper($request->getMethod()).' ';
$message .= '\'http://'.$request->getConnection()->getHost().':'.$request->getConnection()->getPort().'/';
$message .= $request->getPath();
$query = $request->getQuery();
if (!empty($query)) {
$message .= '?'.\http_build_query($query);
}
$message .= '\'';
$data = $request->getData();
if (!empty($data)) {
$message .= ' -d \''.JSON::stringify($data).'\'';
}
return $message;
}
|
[
"public",
"static",
"function",
"convertRequestToCurlCommand",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"message",
"=",
"'curl -X'",
".",
"\\",
"strtoupper",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
".",
"' '",
";",
"$",
"message",
".=",
"'\\'http://'",
".",
"$",
"request",
"->",
"getConnection",
"(",
")",
"->",
"getHost",
"(",
")",
".",
"':'",
".",
"$",
"request",
"->",
"getConnection",
"(",
")",
"->",
"getPort",
"(",
")",
".",
"'/'",
";",
"$",
"message",
".=",
"$",
"request",
"->",
"getPath",
"(",
")",
";",
"$",
"query",
"=",
"$",
"request",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"query",
")",
")",
"{",
"$",
"message",
".=",
"'?'",
".",
"\\",
"http_build_query",
"(",
"$",
"query",
")",
";",
"}",
"$",
"message",
".=",
"'\\''",
";",
"$",
"data",
"=",
"$",
"request",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"message",
".=",
"' -d \\''",
".",
"JSON",
"::",
"stringify",
"(",
"$",
"data",
")",
".",
"'\\''",
";",
"}",
"return",
"$",
"message",
";",
"}"
] |
Converts Request to Curl console command.
@param Request $request
@return string
|
[
"Converts",
"Request",
"to",
"Curl",
"console",
"command",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Util.php#L242-L261
|
train
|
ruflin/Elastica
|
lib/Elastica/Response.php
|
Response.getError
|
public function getError()
{
$error = $this->getFullError();
if (!$error) {
return '';
}
if (\is_string($error)) {
return $error;
}
$rootError = $error;
if (isset($error['root_cause'][0])) {
$rootError = $error['root_cause'][0];
}
$message = $rootError['reason'];
if (isset($rootError['index'])) {
$message .= ' [index: '.$rootError['index'].']';
}
if (isset($error['reason']) && $rootError['reason'] != $error['reason']) {
$message .= ' [reason: '.$error['reason'].']';
}
return $message;
}
|
php
|
public function getError()
{
$error = $this->getFullError();
if (!$error) {
return '';
}
if (\is_string($error)) {
return $error;
}
$rootError = $error;
if (isset($error['root_cause'][0])) {
$rootError = $error['root_cause'][0];
}
$message = $rootError['reason'];
if (isset($rootError['index'])) {
$message .= ' [index: '.$rootError['index'].']';
}
if (isset($error['reason']) && $rootError['reason'] != $error['reason']) {
$message .= ' [reason: '.$error['reason'].']';
}
return $message;
}
|
[
"public",
"function",
"getError",
"(",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"getFullError",
"(",
")",
";",
"if",
"(",
"!",
"$",
"error",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"error",
")",
")",
"{",
"return",
"$",
"error",
";",
"}",
"$",
"rootError",
"=",
"$",
"error",
";",
"if",
"(",
"isset",
"(",
"$",
"error",
"[",
"'root_cause'",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"rootError",
"=",
"$",
"error",
"[",
"'root_cause'",
"]",
"[",
"0",
"]",
";",
"}",
"$",
"message",
"=",
"$",
"rootError",
"[",
"'reason'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"rootError",
"[",
"'index'",
"]",
")",
")",
"{",
"$",
"message",
".=",
"' [index: '",
".",
"$",
"rootError",
"[",
"'index'",
"]",
".",
"']'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"error",
"[",
"'reason'",
"]",
")",
"&&",
"$",
"rootError",
"[",
"'reason'",
"]",
"!=",
"$",
"error",
"[",
"'reason'",
"]",
")",
"{",
"$",
"message",
".=",
"' [reason: '",
".",
"$",
"error",
"[",
"'reason'",
"]",
".",
"']'",
";",
"}",
"return",
"$",
"message",
";",
"}"
] |
Error message.
@return string Error message
|
[
"Error",
"message",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Response.php#L80-L107
|
train
|
ruflin/Elastica
|
lib/Elastica/Response.php
|
Response.isOk
|
public function isOk()
{
$data = $this->getData();
// Bulk insert checks. Check every item
if (isset($data['status'])) {
return $data['status'] >= 200 && $data['status'] <= 300;
}
if (isset($data['items'])) {
if (isset($data['errors']) && true === $data['errors']) {
return false;
}
foreach ($data['items'] as $item) {
if (isset($item['index']['ok']) && false == $item['index']['ok']) {
return false;
}
if (isset($item['index']['status']) && ($item['index']['status'] < 200 || $item['index']['status'] >= 300)) {
return false;
}
}
return true;
}
if ($this->_status >= 200 && $this->_status <= 300) {
// http status is ok
return true;
}
return isset($data['ok']) && $data['ok'];
}
|
php
|
public function isOk()
{
$data = $this->getData();
// Bulk insert checks. Check every item
if (isset($data['status'])) {
return $data['status'] >= 200 && $data['status'] <= 300;
}
if (isset($data['items'])) {
if (isset($data['errors']) && true === $data['errors']) {
return false;
}
foreach ($data['items'] as $item) {
if (isset($item['index']['ok']) && false == $item['index']['ok']) {
return false;
}
if (isset($item['index']['status']) && ($item['index']['status'] < 200 || $item['index']['status'] >= 300)) {
return false;
}
}
return true;
}
if ($this->_status >= 200 && $this->_status <= 300) {
// http status is ok
return true;
}
return isset($data['ok']) && $data['ok'];
}
|
[
"public",
"function",
"isOk",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"// Bulk insert checks. Check every item",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'status'",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"'status'",
"]",
">=",
"200",
"&&",
"$",
"data",
"[",
"'status'",
"]",
"<=",
"300",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'items'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'errors'",
"]",
")",
"&&",
"true",
"===",
"$",
"data",
"[",
"'errors'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"data",
"[",
"'items'",
"]",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'index'",
"]",
"[",
"'ok'",
"]",
")",
"&&",
"false",
"==",
"$",
"item",
"[",
"'index'",
"]",
"[",
"'ok'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'index'",
"]",
"[",
"'status'",
"]",
")",
"&&",
"(",
"$",
"item",
"[",
"'index'",
"]",
"[",
"'status'",
"]",
"<",
"200",
"||",
"$",
"item",
"[",
"'index'",
"]",
"[",
"'status'",
"]",
">=",
"300",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_status",
">=",
"200",
"&&",
"$",
"this",
"->",
"_status",
"<=",
"300",
")",
"{",
"// http status is ok",
"return",
"true",
";",
"}",
"return",
"isset",
"(",
"$",
"data",
"[",
"'ok'",
"]",
")",
"&&",
"$",
"data",
"[",
"'ok'",
"]",
";",
"}"
] |
Checks if the query returned ok.
@return bool True if ok
|
[
"Checks",
"if",
"the",
"query",
"returned",
"ok",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Response.php#L166-L199
|
train
|
ruflin/Elastica
|
lib/Elastica/Response.php
|
Response.getData
|
public function getData()
{
if (null == $this->_response) {
$response = $this->_responseString;
try {
if ($this->getJsonBigintConversion()) {
$response = JSON::parse($response, true, 512, JSON_BIGINT_AS_STRING);
} else {
$response = JSON::parse($response);
}
} catch (JSONParseException $e) {
// leave response as is if parse fails
}
if (empty($response)) {
$response = [];
}
if (\is_string($response)) {
$response = ['message' => $response];
}
$this->_response = $response;
$this->_responseString = '';
}
return $this->_response;
}
|
php
|
public function getData()
{
if (null == $this->_response) {
$response = $this->_responseString;
try {
if ($this->getJsonBigintConversion()) {
$response = JSON::parse($response, true, 512, JSON_BIGINT_AS_STRING);
} else {
$response = JSON::parse($response);
}
} catch (JSONParseException $e) {
// leave response as is if parse fails
}
if (empty($response)) {
$response = [];
}
if (\is_string($response)) {
$response = ['message' => $response];
}
$this->_response = $response;
$this->_responseString = '';
}
return $this->_response;
}
|
[
"public",
"function",
"getData",
"(",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"this",
"->",
"_response",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_responseString",
";",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"getJsonBigintConversion",
"(",
")",
")",
"{",
"$",
"response",
"=",
"JSON",
"::",
"parse",
"(",
"$",
"response",
",",
"true",
",",
"512",
",",
"JSON_BIGINT_AS_STRING",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"JSON",
"::",
"parse",
"(",
"$",
"response",
")",
";",
"}",
"}",
"catch",
"(",
"JSONParseException",
"$",
"e",
")",
"{",
"// leave response as is if parse fails",
"}",
"if",
"(",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"$",
"response",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"response",
")",
")",
"{",
"$",
"response",
"=",
"[",
"'message'",
"=>",
"$",
"response",
"]",
";",
"}",
"$",
"this",
"->",
"_response",
"=",
"$",
"response",
";",
"$",
"this",
"->",
"_responseString",
"=",
"''",
";",
"}",
"return",
"$",
"this",
"->",
"_response",
";",
"}"
] |
Response data array.
@return array Response data array
|
[
"Response",
"data",
"array",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Response.php#L214-L242
|
train
|
ruflin/Elastica
|
lib/Elastica/JSON.php
|
JSON.parse
|
public static function parse($args/* inherit from json_decode */)
{
// extract arguments
$args = \func_get_args();
// default to decoding into an assoc array
if (1 === \count($args)) {
$args[] = true;
}
// run decode
$array = \call_user_func_array('json_decode', $args);
// turn errors into exceptions for easier catching
if ($error = self::getJsonLastErrorMsg()) {
throw new JSONParseException($error);
}
// output
return $array;
}
|
php
|
public static function parse($args/* inherit from json_decode */)
{
// extract arguments
$args = \func_get_args();
// default to decoding into an assoc array
if (1 === \count($args)) {
$args[] = true;
}
// run decode
$array = \call_user_func_array('json_decode', $args);
// turn errors into exceptions for easier catching
if ($error = self::getJsonLastErrorMsg()) {
throw new JSONParseException($error);
}
// output
return $array;
}
|
[
"public",
"static",
"function",
"parse",
"(",
"$",
"args",
"/* inherit from json_decode */",
")",
"{",
"// extract arguments",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"// default to decoding into an assoc array",
"if",
"(",
"1",
"===",
"\\",
"count",
"(",
"$",
"args",
")",
")",
"{",
"$",
"args",
"[",
"]",
"=",
"true",
";",
"}",
"// run decode",
"$",
"array",
"=",
"\\",
"call_user_func_array",
"(",
"'json_decode'",
",",
"$",
"args",
")",
";",
"// turn errors into exceptions for easier catching",
"if",
"(",
"$",
"error",
"=",
"self",
"::",
"getJsonLastErrorMsg",
"(",
")",
")",
"{",
"throw",
"new",
"JSONParseException",
"(",
"$",
"error",
")",
";",
"}",
"// output",
"return",
"$",
"array",
";",
"}"
] |
Parse JSON string to an array.
@see http://php.net/manual/en/function.json-decode.php
@see http://php.net/manual/en/function.json-last-error.php
@param string $args,... JSON string to parse
@throws JSONParseException
@return array PHP array representation of JSON string
|
[
"Parse",
"JSON",
"string",
"to",
"an",
"array",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/JSON.php#L24-L44
|
train
|
ruflin/Elastica
|
lib/Elastica/JSON.php
|
JSON.stringify
|
public static function stringify($args/* inherit from json_encode */)
{
// extract arguments
$args = \func_get_args();
// run encode and output
$string = \call_user_func_array('json_encode', $args);
// turn errors into exceptions for easier catching
if ($error = self::getJsonLastErrorMsg()) {
throw new JSONParseException($error);
}
// output
return $string;
}
|
php
|
public static function stringify($args/* inherit from json_encode */)
{
// extract arguments
$args = \func_get_args();
// run encode and output
$string = \call_user_func_array('json_encode', $args);
// turn errors into exceptions for easier catching
if ($error = self::getJsonLastErrorMsg()) {
throw new JSONParseException($error);
}
// output
return $string;
}
|
[
"public",
"static",
"function",
"stringify",
"(",
"$",
"args",
"/* inherit from json_encode */",
")",
"{",
"// extract arguments",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"// run encode and output",
"$",
"string",
"=",
"\\",
"call_user_func_array",
"(",
"'json_encode'",
",",
"$",
"args",
")",
";",
"// turn errors into exceptions for easier catching",
"if",
"(",
"$",
"error",
"=",
"self",
"::",
"getJsonLastErrorMsg",
"(",
")",
")",
"{",
"throw",
"new",
"JSONParseException",
"(",
"$",
"error",
")",
";",
"}",
"// output",
"return",
"$",
"string",
";",
"}"
] |
Convert input to JSON string with standard options.
@see http://php.net/manual/en/function.json-encode.php
@see http://php.net/manual/en/function.json-last-error.php
@param mixed $args,... Target to stringify
@throws JSONParseException
@return string Valid JSON representation of $input
|
[
"Convert",
"input",
"to",
"JSON",
"string",
"with",
"standard",
"options",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/JSON.php#L58-L73
|
train
|
ruflin/Elastica
|
lib/Elastica/Aggregation/Histogram.php
|
Histogram.setOrder
|
public function setOrder(string $order, string $direction): self
{
return $this->setParam('order', [$order => $direction]);
}
|
php
|
public function setOrder(string $order, string $direction): self
{
return $this->setParam('order', [$order => $direction]);
}
|
[
"public",
"function",
"setOrder",
"(",
"string",
"$",
"order",
",",
"string",
"$",
"direction",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"setParam",
"(",
"'order'",
",",
"[",
"$",
"order",
"=>",
"$",
"direction",
"]",
")",
";",
"}"
] |
Set the bucket sort order.
@param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field
@param string $direction "asc" or "desc"
@return $this
|
[
"Set",
"the",
"bucket",
"sort",
"order",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Aggregation/Histogram.php#L44-L47
|
train
|
ruflin/Elastica
|
lib/Elastica/Query/Terms.php
|
Terms.setTerms
|
public function setTerms(string $key, array $terms): self
{
$this->_key = $key;
$this->_terms = \array_values($terms);
return $this;
}
|
php
|
public function setTerms(string $key, array $terms): self
{
$this->_key = $key;
$this->_terms = \array_values($terms);
return $this;
}
|
[
"public",
"function",
"setTerms",
"(",
"string",
"$",
"key",
",",
"array",
"$",
"terms",
")",
":",
"self",
"{",
"$",
"this",
"->",
"_key",
"=",
"$",
"key",
";",
"$",
"this",
"->",
"_terms",
"=",
"\\",
"array_values",
"(",
"$",
"terms",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets key and terms for the query.
@param string $key terms key
@param array $terms terms for the query
@return $this
|
[
"Sets",
"key",
"and",
"terms",
"for",
"the",
"query",
"."
] |
9bda1596f79a28534dfd7b3513443478ad152e4e
|
https://github.com/ruflin/Elastica/blob/9bda1596f79a28534dfd7b3513443478ad152e4e/lib/Elastica/Query/Terms.php#L50-L56
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.