PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Elastica/Filter/Range.php

https://github.com/nordsee/Elastica
PHP | 61 lines | 22 code | 7 blank | 32 comment | 1 complexity | 01120ed7b84a4174fd1d76d56ac7e671 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. namespace Elastica\Filter;
  3. /**
  4. * Range Filter
  5. *
  6. * @category Xodoa
  7. * @package Elastica
  8. * @author Nicolas Ruflin <spam@ruflin.com>
  9. * @link http://www.elasticsearch.org/guide/reference/query-dsl/range-filter.html
  10. */
  11. class Range extends AbstractFilter
  12. {
  13. /**
  14. * Fields
  15. *
  16. * @var array Fields
  17. */
  18. protected $_fields = array();
  19. /**
  20. * Construct range filter
  21. *
  22. * @param string|bool $fieldName Field name
  23. * @param array $args Field arguments
  24. */
  25. public function __construct($fieldName = false, array $args = array())
  26. {
  27. if ($fieldName) {
  28. $this->addField($fieldName, $args);
  29. }
  30. }
  31. /**
  32. * Ads a field with arguments to the range query
  33. *
  34. * @param string $fieldName Field name
  35. * @param array $args Field arguments
  36. * @return \Elastica\Filter\Range
  37. */
  38. public function addField($fieldName, array $args)
  39. {
  40. $this->_fields[$fieldName] = $args;
  41. return $this;
  42. }
  43. /**
  44. * Converts object to array
  45. *
  46. * @see \Elastica\Filter\AbstractFilter::toArray()
  47. * @return array Filter array
  48. */
  49. public function toArray()
  50. {
  51. $this->setParams($this->_fields);
  52. return parent::toArray();
  53. }
  54. }