123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace Mall\Framework\SearchClient\DSL;
- class RangeQuery {
- protected $fieldname = null;
- protected $from = null;
- protected $to = null;
- protected $includeLower = null;
- protected $includeUpper = null;
- protected $boost = null;
-
-
- public function __construct(array $options=array()) {
- $this->fieldname = key($options);
- $values = current($options);
- if (is_array($values)) {
- foreach ($values as $key => $val)
- $this->$key = $val;
- }
- }
-
-
- public function fieldname($value) {
- $this->fieldname = $value;
- return $this;
- }
-
- public function from($value) {
- $this->from = $value;
- return $this;
- }
-
- public function to($value) {
- $this->to = $value;
- return $this;
- }
-
- public function includeLower($value) {
- $this->includeLower = $value;
- return $this;
- }
-
- public function includeUpper($value) {
- $this->includeUpper = $value;
- return $this;
- }
-
- public function boost($value) {
- $this->boost = $value;
- return $this;
- }
-
- public function build() {
- $built = array();
- if ($this->fieldname) {
- $built[$this->fieldname] = array();
- foreach (array("from","to","includeLower","includeUpper", "boost") as $opt) {
- if ($this->$opt !== null)
- $built[$this->fieldname][$opt] = $this->$opt;
- }
- if (count($built[$this->fieldname]) == 0)
- throw new \ElasticSearch\Exception("Empty RangeQuery cant be created");
- }
- return $built;
- }
- }
|