Skip to content

Commit

Permalink
Add TermVector Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Feb 11, 2014
1 parent 74da187 commit c67c0dd
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,45 @@ public function mpercolate($params = array())
}


/**
* $params['index'] = (string) Default index for items which don't provide one
* ['type'] = (string) Default document type for items which don't provide one
* ['term_statistics'] = (boolean) Specifies if total term frequency and document frequency should be returned. Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\"."
* ['field_statistics'] = (boolean) Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\"."
* ['fields'] = (list) A comma-separated list of fields to return. Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\"."
* ['offsets'] = (boolean) Specifies if term offsets should be returned. Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\"."
* ['positions'] = (boolean) Specifies if term positions should be returned. Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\"."
* ['payloads'] = (boolean) Specifies if term payloads should be returned. Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\".
* ['preference'] = (string) Specify the node or shard the operation should be performed on (default: random) .Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\".
* ['routing'] = (string) Specific routing value. Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\".
* ['parent'] = (string) Parent id of documents. Applies to all returned documents unless otherwise specified in body \"params\" or \"docs\".
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function termvector($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\TermVector $endpoint */
$endpoint = $endpointBuilder('TermVector');
$endpoint->setIndex($index)
->setType($type)
->setID($id)
->setBody($body);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}


/**
* $params['index'] = (string) Default index for items which don't provide one
* ['type'] = (string) Default document type for items which don't provide one
Expand Down
93 changes: 93 additions & 0 deletions src/Elasticsearch/Endpoints/TermVector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* User: zach
* Date: 05/31/2013
* Time: 16:47:11 pm
*/

namespace Elasticsearch\Endpoints;

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

/**
* Class TermVector
* @package Elasticsearch\Endpoints
*/
class TermVector 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 TermVector'
);
}
if (isset($this->type) !== true) {
throw new Exceptions\RuntimeException(
'type is required for TermVector'
);
}
if (isset($this->id) !== true) {
throw new Exceptions\RuntimeException(
'id is required for TermVector'
);
}

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

return $uri;

}

/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array(
'term_statistics',
'field_statistics',
'fields',
'offsets',
'positions',
'payloads',
'preference',
'routing',
'parent'
);
}

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

0 comments on commit c67c0dd

Please sign in to comment.