Suggest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Elasticsearch\Endpoints;
  3. use Elasticsearch\Common\Exceptions;
  4. /**
  5. * Class Suggest
  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 Suggest 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. * @return string
  31. */
  32. public function getURI()
  33. {
  34. $index = $this->index;
  35. $uri = "/_suggest";
  36. if (isset($index) === true) {
  37. $uri = "/$index/_suggest";
  38. }
  39. return $uri;
  40. }
  41. /**
  42. * @return string[]
  43. */
  44. public function getParamWhitelist()
  45. {
  46. return array(
  47. 'ignore_unavailable',
  48. 'allow_no_indices',
  49. 'expand_wildcards',
  50. 'preference',
  51. 'routing',
  52. 'source',
  53. );
  54. }
  55. /**
  56. * @return array
  57. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  58. */
  59. public function getBody()
  60. {
  61. if (isset($this->body) !== true) {
  62. throw new Exceptions\RuntimeException('Body is required for Suggest');
  63. }
  64. return $this->body;
  65. }
  66. /**
  67. * @return string
  68. */
  69. public function getMethod()
  70. {
  71. return 'POST';
  72. }
  73. }