Search.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Elasticsearch\Endpoints;
  3. use Elasticsearch\Common\Exceptions\InvalidArgumentException;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class Search
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints
  10. * @author Zachary Tong <zach@elastic.co>
  11. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  12. * @link http://elastic.co
  13. */
  14. class Search extends AbstractEndpoint
  15. {
  16. /**
  17. * @param array $body
  18. *
  19. * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  20. * @return $this
  21. */
  22. public function setBody($body)
  23. {
  24. if (isset($body) !== true) {
  25. return $this;
  26. }
  27. $this->body = $body;
  28. return $this;
  29. }
  30. /**
  31. * @return string
  32. */
  33. public function getURI()
  34. {
  35. $index = $this->index;
  36. $type = $this->type;
  37. $uri = "/_search";
  38. if (isset($index) === true && isset($type) === true) {
  39. $uri = "/$index/$type/_search";
  40. } elseif (isset($index) === true) {
  41. $uri = "/$index/_search";
  42. } elseif (isset($type) === true) {
  43. $uri = "/_all/$type/_search";
  44. }
  45. return $uri;
  46. }
  47. /**
  48. * @return string[]
  49. */
  50. public function getParamWhitelist()
  51. {
  52. return array(
  53. 'analyzer',
  54. 'analyze_wildcard',
  55. 'default_operator',
  56. 'df',
  57. 'explain',
  58. 'from',
  59. 'ignore_unavailable',
  60. 'allow_no_indices',
  61. 'expand_wildcards',
  62. 'indices_boost',
  63. 'lenient',
  64. 'lowercase_expanded_terms',
  65. 'preference',
  66. 'q',
  67. 'query_cache',
  68. 'request_cache',
  69. 'routing',
  70. 'scroll',
  71. 'search_type',
  72. 'size',
  73. 'slice',
  74. 'sort',
  75. 'source',
  76. '_source',
  77. '_source_exclude',
  78. '_source_include',
  79. 'stats',
  80. 'suggest_field',
  81. 'suggest_mode',
  82. 'suggest_size',
  83. 'suggest_text',
  84. 'timeout',
  85. 'version',
  86. 'fielddata_fields',
  87. 'docvalue_fields',
  88. 'filter_path',
  89. 'terminate_after',
  90. 'stored_fields',
  91. 'batched_reduce_size',
  92. 'typed_keys',
  93. 'pre_filter_shard_size'
  94. );
  95. }
  96. /**
  97. * @return string
  98. */
  99. public function getMethod()
  100. {
  101. return 'GET';
  102. }
  103. }