123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php // vim:set ts=4 sw=4 et:
- namespace Mall\Framework\SearchClient\DSL;
- /**
- * This file is part of the ElasticSearch PHP client
- *
- * (c) Raymond Julin <raymond.julin@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- /**
- * Range queries
- *
- * @author Raymond Julin <raymond.julin@gmail.com>
- * @package ElasticSearchClient
- * @since 0.1
- * Created: 2010-07-24
- */
- class RangeQuery {
- protected $fieldname = null;
- protected $from = null;
- protected $to = null;
- protected $includeLower = null;
- protected $includeUpper = null;
- protected $boost = null;
-
- /**
- * Construct new RangeQuery component
- *
- * @return \Mall\Framework\SearchClient\DSL\RangeQuery
- * @param array $options
- */
- 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;
- }
- }
-
- /**
- * Setters
- *
- * @return \Mall\Framework\SearchClient\DSL\RangeQuery
- * @param mixed $value
- */
- public function fieldname($value) {
- $this->fieldname = $value;
- return $this;
- }
- /**
- * @param $value
- * @return \Mall\Framework\SearchClient\DSL\RangeQuery $this
- */
- public function from($value) {
- $this->from = $value;
- return $this;
- }
- /**
- * @param $value
- * @return \Mall\Framework\SearchClient\DSL\RangeQuery $this
- */
- public function to($value) {
- $this->to = $value;
- return $this;
- }
- /**
- * @param $value
- * @return \Mall\Framework\SearchClient\DSL\RangeQuery $this
- */
- public function includeLower($value) {
- $this->includeLower = $value;
- return $this;
- }
- /**
- * @param $value
- * @return \Mall\Framework\SearchClient\DSL\RangeQuery $this
- */
- public function includeUpper($value) {
- $this->includeUpper = $value;
- return $this;
- }
- /**
- * @param $value
- * @return \Mall\Framework\SearchClient\DSL\RangeQuery $this
- */
- public function boost($value) {
- $this->boost = $value;
- return $this;
- }
- /**
- * Build to array
- *
- * @throws \Mall\Framework\SearchClient\Exception
- * @return array
- */
- 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;
- }
- }
|