Skip to content

Commit

Permalink
Add MTermVectors Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Feb 11, 2014
1 parent ce39316 commit ebd3ff3
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,44 @@ 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
* ['ids'] = (list) A comma-separated list of documents ids. You must define ids as parameter or set \"ids\" or \"docs\" in the request body
* ['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 mtermvectors($params = array())
{
$index = $this->extractArgument($params, 'index');
$type = $this->extractArgument($params, 'type');
$body = $this->extractArgument($params, 'body');

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

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


/**
* $params['id'] = (string) The document ID (Required)
* ['index'] = (string) The name of the index (Required)
Expand Down
71 changes: 71 additions & 0 deletions src/Elasticsearch/Endpoints/MTermVectors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* User: zach
* Date: 05/31/2013
* Time: 16:47:11 pm
*/

namespace Elasticsearch\Endpoints;

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

/**
* Class MTermVectors
* @package Elasticsearch\Endpoints
*/
class MTermVectors 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;
}

/**
* @return string
*/
protected function getURI()
{
return $this->getOptionalURI('_mtermvectors');

}

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

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

0 comments on commit ebd3ff3

Please sign in to comment.