TermVectors.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Elasticsearch\Endpoints;
  3. use Elasticsearch\Common\Exceptions;
  4. /**
  5. * Class TermVectors
  6. *
  7. * @category Elasticsearch
  8. * @package Elasticsearch\Endpoints
  9. * @author Zachary Tong <zach@elastic.co>
  10. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  11. * @link http://elastic.co
  12. */
  13. class TermVectors extends AbstractEndpoint
  14. {
  15. /**
  16. * @param array $body
  17. *
  18. * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  19. * @return $this
  20. */
  21. public function setBody($body)
  22. {
  23. if (isset($body) !== true) {
  24. return $this;
  25. }
  26. $this->body = $body;
  27. return $this;
  28. }
  29. /**
  30. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  31. * @return string
  32. */
  33. public function getURI()
  34. {
  35. if (isset($this->index) !== true) {
  36. throw new Exceptions\RuntimeException(
  37. 'index is required for TermVectors'
  38. );
  39. }
  40. if (isset($this->type) !== true) {
  41. throw new Exceptions\RuntimeException(
  42. 'type is required for TermVectors'
  43. );
  44. }
  45. if (isset($this->id) !== true && isset($this->body['doc']) !== true) {
  46. throw new Exceptions\RuntimeException(
  47. 'id or doc is required for TermVectors'
  48. );
  49. }
  50. $index = $this->index;
  51. $type = $this->type;
  52. $id = $this->id;
  53. $uri = "/$index/$type/_termvectors";
  54. if ($id !== null) {
  55. $uri = "/$index/$type/$id/_termvectors";
  56. }
  57. return $uri;
  58. }
  59. /**
  60. * @return string[]
  61. */
  62. public function getParamWhitelist()
  63. {
  64. return array(
  65. 'term_statistics',
  66. 'field_statistics',
  67. 'fields',
  68. 'offsets',
  69. 'positions',
  70. 'payloads',
  71. 'preference',
  72. 'routing',
  73. 'parent',
  74. 'realtime'
  75. );
  76. }
  77. /**
  78. * @return string
  79. */
  80. public function getMethod()
  81. {
  82. return 'POST';
  83. }
  84. }