Skip to content

Commit

Permalink
Add CountPercolate Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Feb 11, 2014
1 parent ebd3ff3 commit 054e60a
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,46 @@ public function count($params = array())
return $response['data'];
}

/**
* $params['index'] = (list) A comma-separated list of indices to restrict the results
* ['type'] = (list) A comma-separated list of types to restrict the results
* ['id'] = (string) ID of document
* ['ignore_unavailable'] = (boolean) Whether specified concrete indices should be ignored when unavailable (missing or closed)
* ['preference'] = (string) Specify the node or shard the operation should be performed on (default: random)
* ['routing'] = (string) Specific routing value
* ['allow_no_indices'] = (boolean) Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)
* ['body'] = (array) A query to restrict the results (optional)
* ['ignore_unavailable'] = (bool) Whether specified concrete indices should be ignored when unavailable (missing or closed)
* ['percolate_index'] = (string) The index to count percolate the document into. Defaults to index.
* ['expand_wildcards'] = (enum) Whether to expand wildcard expression to concrete indices that are open, closed or both.
* ['version'] = (number) Explicit version number for concurrency control
* ['version_type'] = (enum) Specific version type
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function countPercolate($params = array())
{
$index = $this->extractArgument($params, 'index');
$type = $this->extractArgument($params, 'type');
$id = $this->extractArgument($params, 'id');
$body = $this->extractArgument($params, 'body');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\CountPercolate $endpoint */
$endpoint = $endpointBuilder('CountPercolate');
$endpoint->setIndex($index)
->setType($type)
->setID($id)
->setBody($body);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}


/**
* $params['index'] = (string) The name of the index with a registered percolator query (Required)
Expand Down
100 changes: 100 additions & 0 deletions src/Elasticsearch/Endpoints/CountPercolate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* User: zach
* Date: 01/20/2014
* Time: 14:34:49 pm
*/

namespace Elasticsearch\Endpoints;

use Elasticsearch\Endpoints\AbstractEndpoint;
use Elasticsearch\Common\Exceptions;

/**
* Class CountPercolate
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/

class CountPercolate extends AbstractEndpoint
{
/**
* @param array $body
*
* @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
* @return $this
*/
public function setBody($body)
{
if (isset($body) !== true) {
return $this;
}


$this->body = $body;
return $this;
}


/**
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
* @return string
*/
protected function getURI()
{
if (isset($this->index) !== true) {
throw new Exceptions\RuntimeException(
'index is required for CountPercolate'
);
}

if (isset($this->type) !== true) {
throw new Exceptions\RuntimeException(
'type is required for CountPercolate'
);
}

$index = $this->index;
$type = $this->type;
$id = $this->id;
$uri = "/$index/$type/_percolate/count";

if (isset($id) === true) {
$uri = "/$index/$type/$id/_percolate/count";
}

return $uri;
}


/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array(
'routing',
'preference',
'ignore_unavailable',
'allow_no_indices',
'expand_wildcards',
'percolate_index',
'percolate_type',
'version',
'version_type'
);
}


/**
* @return string
*/
protected function getMethod()
{
return 'GET';
}
}

0 comments on commit 054e60a

Please sign in to comment.