PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Elastica/QueryBuilder/DSL/Aggregation.php

http://github.com/ruflin/Elastica
PHP | 470 lines | 154 code | 31 blank | 285 comment | 0 complexity | 9ddc85711e0b475ed9a23a8e68b29986 MD5 | raw file
  1. <?php
  2. namespace Elastica\QueryBuilder\DSL;
  3. use Elastica\Aggregation\Avg;
  4. use Elastica\Aggregation\Cardinality;
  5. use Elastica\Aggregation\DateHistogram;
  6. use Elastica\Aggregation\DateRange;
  7. use Elastica\Aggregation\ExtendedStats;
  8. use Elastica\Aggregation\Filter as FilterAggregation;
  9. use Elastica\Aggregation\Filters;
  10. use Elastica\Aggregation\GeoDistance;
  11. use Elastica\Aggregation\GeohashGrid;
  12. use Elastica\Aggregation\GlobalAggregation;
  13. use Elastica\Aggregation\Histogram;
  14. use Elastica\Aggregation\IpRange;
  15. use Elastica\Aggregation\Max;
  16. use Elastica\Aggregation\Min;
  17. use Elastica\Aggregation\Missing;
  18. use Elastica\Aggregation\Nested;
  19. use Elastica\Aggregation\Percentiles;
  20. use Elastica\Aggregation\Range;
  21. use Elastica\Aggregation\ReverseNested;
  22. use Elastica\Aggregation\ScriptedMetric;
  23. use Elastica\Aggregation\SignificantTerms;
  24. use Elastica\Aggregation\Stats;
  25. use Elastica\Aggregation\Sum;
  26. use Elastica\Aggregation\Terms;
  27. use Elastica\Aggregation\TopHits;
  28. use Elastica\Aggregation\ValueCount;
  29. use Elastica\Exception\NotImplementedException;
  30. use Elastica\Filter\AbstractFilter;
  31. use Elastica\QueryBuilder\DSL;
  32. /**
  33. * elasticsearch aggregation DSL.
  34. *
  35. * @author Manuel Andreo Garcia <andreo.garcia@googlemail.com>
  36. *
  37. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html
  38. */
  39. class Aggregation implements DSL
  40. {
  41. /**
  42. * must return type for QueryBuilder usage.
  43. *
  44. * @return string
  45. */
  46. public function getType()
  47. {
  48. return DSL::TYPE_AGGREGATION;
  49. }
  50. /**
  51. * min aggregation.
  52. *
  53. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html
  54. *
  55. * @param string $name
  56. *
  57. * @return Min
  58. */
  59. public function min($name)
  60. {
  61. return new Min($name);
  62. }
  63. /**
  64. * max aggregation.
  65. *
  66. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html
  67. *
  68. * @param string $name
  69. *
  70. * @return Max
  71. */
  72. public function max($name)
  73. {
  74. return new Max($name);
  75. }
  76. /**
  77. * sum aggregation.
  78. *
  79. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html
  80. *
  81. * @param string $name
  82. *
  83. * @return Sum
  84. */
  85. public function sum($name)
  86. {
  87. return new Sum($name);
  88. }
  89. /**
  90. * avg aggregation.
  91. *
  92. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
  93. *
  94. * @param string $name
  95. *
  96. * @return Avg
  97. */
  98. public function avg($name)
  99. {
  100. return new Avg($name);
  101. }
  102. /**
  103. * stats aggregation.
  104. *
  105. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
  106. *
  107. * @param string $name
  108. *
  109. * @return Stats
  110. */
  111. public function stats($name)
  112. {
  113. return new Stats($name);
  114. }
  115. /**
  116. * extended stats aggregation.
  117. *
  118. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html
  119. *
  120. * @param string $name
  121. *
  122. * @return ExtendedStats
  123. */
  124. public function extended_stats($name)
  125. {
  126. return new ExtendedStats($name);
  127. }
  128. /**
  129. * value count aggregation.
  130. *
  131. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html
  132. *
  133. * @param string $name
  134. * @param string $field
  135. *
  136. * @return ValueCount
  137. */
  138. public function value_count($name, $field)
  139. {
  140. return new ValueCount($name, $field);
  141. }
  142. /**
  143. * percentiles aggregation.
  144. *
  145. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
  146. *
  147. * @param string $name the name of this aggregation
  148. * @param string $field the field on which to perform this aggregation
  149. *
  150. * @return Percentiles
  151. */
  152. public function percentiles($name, $field = null)
  153. {
  154. return new Percentiles($name, $field);
  155. }
  156. /**
  157. * percentile ranks aggregation.
  158. *
  159. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-rank-aggregation.html
  160. *
  161. * @param string $name
  162. */
  163. public function percentile_ranks($name)
  164. {
  165. throw new NotImplementedException();
  166. }
  167. /**
  168. * cardinality aggregation.
  169. *
  170. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
  171. *
  172. * @param string $name
  173. *
  174. * @return Cardinality
  175. */
  176. public function cardinality($name)
  177. {
  178. return new Cardinality($name);
  179. }
  180. /**
  181. * geo bounds aggregation.
  182. *
  183. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geobounds-aggregation.html
  184. *
  185. * @param string $name
  186. */
  187. public function geo_bounds($name)
  188. {
  189. throw new NotImplementedException();
  190. }
  191. /**
  192. * top hits aggregation.
  193. *
  194. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html
  195. *
  196. * @param string $name
  197. *
  198. * @return TopHits
  199. */
  200. public function top_hits($name)
  201. {
  202. return new TopHits($name);
  203. }
  204. /**
  205. * scripted metric aggregation.
  206. *
  207. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html
  208. *
  209. * @param string $name
  210. * @param string|null $initScript
  211. * @param string|null $mapScript
  212. * @param string|null $combineScript
  213. * @param string|null $reduceScript
  214. *
  215. * @return ScriptedMetric
  216. */
  217. public function scripted_metric($name, $initScript = null, $mapScript = null, $combineScript = null, $reduceScript = null)
  218. {
  219. return new ScriptedMetric($name, $initScript, $mapScript, $combineScript, $reduceScript);
  220. }
  221. /**
  222. * global aggregation.
  223. *
  224. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html
  225. *
  226. * @param string $name
  227. *
  228. * @return GlobalAggregation
  229. */
  230. public function global_agg($name)
  231. {
  232. return new GlobalAggregation($name);
  233. }
  234. /**
  235. * filter aggregation.
  236. *
  237. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
  238. *
  239. * @param string $name
  240. * @param AbstractFilter $filter
  241. *
  242. * @return FilterAggregation
  243. */
  244. public function filter($name, $filter = null)
  245. {
  246. return new FilterAggregation($name, $filter);
  247. }
  248. /**
  249. * filters aggregation.
  250. *
  251. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html
  252. *
  253. * @param string $name
  254. *
  255. * @return Filters
  256. */
  257. public function filters($name)
  258. {
  259. return new Filters($name);
  260. }
  261. /**
  262. * missing aggregation.
  263. *
  264. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html
  265. *
  266. * @param string $name
  267. * @param string $field
  268. *
  269. * @return Missing
  270. */
  271. public function missing($name, $field)
  272. {
  273. return new Missing($name, $field);
  274. }
  275. /**
  276. * nested aggregation.
  277. *
  278. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html
  279. *
  280. * @param string $name
  281. * @param string $path the nested path for this aggregation
  282. *
  283. * @return Nested
  284. */
  285. public function nested($name, $path)
  286. {
  287. return new Nested($name, $path);
  288. }
  289. /**
  290. * reverse nested aggregation.
  291. *
  292. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
  293. *
  294. * @param string $name The name of this aggregation
  295. * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document.
  296. *
  297. * @return ReverseNested
  298. */
  299. public function reverse_nested($name, $path = null)
  300. {
  301. return new ReverseNested($name);
  302. }
  303. /**
  304. * children aggregation.
  305. *
  306. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-children-aggregation.html
  307. *
  308. * @param string $name
  309. */
  310. public function children($name)
  311. {
  312. throw new NotImplementedException();
  313. }
  314. /**
  315. * terms aggregation.
  316. *
  317. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
  318. *
  319. * @param string $name
  320. *
  321. * @return Terms
  322. */
  323. public function terms($name)
  324. {
  325. return new Terms($name);
  326. }
  327. /**
  328. * significant terms aggregation.
  329. *
  330. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html
  331. *
  332. * @param string $name
  333. *
  334. * @return SignificantTerms
  335. */
  336. public function significant_terms($name)
  337. {
  338. return new SignificantTerms($name);
  339. }
  340. /**
  341. * range aggregation.
  342. *
  343. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html
  344. *
  345. * @param string $name
  346. *
  347. * @return Range
  348. */
  349. public function range($name)
  350. {
  351. return new Range($name);
  352. }
  353. /**
  354. * date range aggregation.
  355. *
  356. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html
  357. *
  358. * @param string $name
  359. *
  360. * @return DateRange
  361. */
  362. public function date_range($name)
  363. {
  364. return new DateRange($name);
  365. }
  366. /**
  367. * ipv4 range aggregation.
  368. *
  369. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html
  370. *
  371. * @param string $name
  372. * @param string $field
  373. *
  374. * @return IpRange
  375. */
  376. public function ipv4_range($name, $field)
  377. {
  378. return new IpRange($name, $field);
  379. }
  380. /**
  381. * histogram aggregation.
  382. *
  383. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
  384. *
  385. * @param string $name the name of this aggregation
  386. * @param string $field the name of the field on which to perform the aggregation
  387. * @param int $interval the interval by which documents will be bucketed
  388. *
  389. * @return Histogram
  390. */
  391. public function histogram($name, $field, $interval)
  392. {
  393. return new Histogram($name, $field, $interval);
  394. }
  395. /**
  396. * date histogram aggregation.
  397. *
  398. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
  399. *
  400. * @param string $name the name of this aggregation
  401. * @param string $field the name of the field on which to perform the aggregation
  402. * @param int $interval the interval by which documents will be bucketed
  403. *
  404. * @return DateHistogram
  405. */
  406. public function date_histogram($name, $field, $interval)
  407. {
  408. return new DateHistogram($name, $field, $interval);
  409. }
  410. /**
  411. * geo distance aggregation.
  412. *
  413. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html
  414. *
  415. * @param string $name the name if this aggregation
  416. * @param string $field the field on which to perform this aggregation
  417. * @param string|array $origin the point from which distances will be calculated
  418. *
  419. * @return GeoDistance
  420. */
  421. public function geo_distance($name, $field, $origin)
  422. {
  423. return new GeoDistance($name, $field, $origin);
  424. }
  425. /**
  426. * geohash grid aggregation.
  427. *
  428. * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html
  429. *
  430. * @param string $name the name of this aggregation
  431. * @param string $field the field on which to perform this aggregation
  432. *
  433. * @return GeohashGrid
  434. */
  435. public function geohash_grid($name, $field)
  436. {
  437. return new GeohashGrid($name, $field);
  438. }
  439. }