12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace Mall\Framework\SearchClient\DSL;
- class Builder {
- protected $dsl = array();
- private $explain = null;
- private $from = null;
- private $size = null;
- private $fields = null;
- private $query = null;
- private $facets = null;
- private $sort = null;
-
- public function __construct(array $options=array()) {
- foreach ($options as $key => $value)
- $this->$key = $value;
- }
-
- public function query(array $options=array()) {
- if (!($this->query instanceof Query))
- $this->query = new Query($options);
- return $this->query;
- }
-
- public function build() {
- $built = array();
- if ($this->from != null)
- $built['from'] = $this->from;
- if ($this->size != null)
- $built['size'] = $this->size;
- if ($this->sort && is_array($this->sort))
- $built['sort'] = $this->sort;
- if (!$this->query)
- throw new \ElasticSearch\Exception("Query must be specified");
- else
- $built['query'] = $this->query->build();
- return $built;
- }
- }
|