AbstractTermsAggregation.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace Elastica\Aggregation;
  3. /**
  4. * Class AbstractTermsAggregation.
  5. */
  6. abstract class AbstractTermsAggregation extends AbstractSimpleAggregation
  7. {
  8. /**
  9. * Set the minimum number of documents in which a term must appear in order to be returned in a bucket.
  10. *
  11. * @param int $count
  12. *
  13. * @return $this
  14. */
  15. public function setMinimumDocumentCount($count)
  16. {
  17. return $this->setParam('min_doc_count', $count);
  18. }
  19. /**
  20. * Filter documents to include based on a regular expression.
  21. *
  22. * @param string $pattern a regular expression
  23. * @param string $flags Java Pattern flags
  24. *
  25. * @return $this
  26. */
  27. public function setInclude($pattern, $flags = null)
  28. {
  29. if (is_null($flags)) {
  30. return $this->setParam('include', $pattern);
  31. }
  32. return $this->setParam('include', [
  33. 'pattern' => $pattern,
  34. 'flags' => $flags,
  35. ]);
  36. }
  37. /**
  38. * Filter documents to exclude based on a regular expression.
  39. *
  40. * @param string $pattern a regular expression
  41. * @param string $flags Java Pattern flags
  42. *
  43. * @return $this
  44. */
  45. public function setExclude($pattern, $flags = null)
  46. {
  47. if (is_null($flags)) {
  48. return $this->setParam('exclude', $pattern);
  49. }
  50. return $this->setParam('exclude', [
  51. 'pattern' => $pattern,
  52. 'flags' => $flags,
  53. ]);
  54. }
  55. /**
  56. * Sets the amount of terms to be returned.
  57. *
  58. * @param int $size the amount of terms to be returned
  59. *
  60. * @return $this
  61. */
  62. public function setSize($size)
  63. {
  64. return $this->setParam('size', $size);
  65. }
  66. /**
  67. * Sets how many terms the coordinating node will request from each shard.
  68. *
  69. * @param int $shard_size the amount of terms to be returned
  70. *
  71. * @return $this
  72. */
  73. public function setShardSize($shard_size)
  74. {
  75. return $this->setParam('shard_size', $shard_size);
  76. }
  77. /**
  78. * Instruct Elasticsearch to use direct field data or ordinals of the field values to execute this aggregation.
  79. * The execution hint will be ignored if it is not applicable.
  80. *
  81. * @param string $hint map or ordinals
  82. *
  83. * @return $this
  84. */
  85. public function setExecutionHint($hint)
  86. {
  87. return $this->setParam('execution_hint', $hint);
  88. }
  89. }