diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/lib/Elastica/QueryBuilder.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/QueryBuilder.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/QueryBuilder.php | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/QueryBuilder.php b/vendor/ruflin/elastica/lib/Elastica/QueryBuilder.php new file mode 100644 index 00000000..477c4525 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/QueryBuilder.php @@ -0,0 +1,114 @@ +<?php +namespace Elastica; + +use Elastica\Exception\QueryBuilderException; +use Elastica\QueryBuilder\DSL; +use Elastica\QueryBuilder\Facade; +use Elastica\QueryBuilder\Version; +use Elastica\QueryBuilder\Version\Version150; + +/** + * Query Builder. + * + * @author Manuel Andreo Garcia <andreo.garcia@googlemail.com> + */ +class QueryBuilder +{ + /** + * @var Version + */ + private $_version; + + /** + * @var Facade[] + */ + private $_facades = array(); + + /** + * Constructor. + * + * @param Version $version + */ + public function __construct(Version $version = null) + { + $this->_version = $version ?: new Version150(); + + $this->addDSL(new DSL\Query()); + $this->addDSL(new DSL\Filter()); + $this->addDSL(new DSL\Aggregation()); + $this->addDSL(new DSL\Suggest()); + } + + /** + * Returns Facade for custom DSL object. + * + * @param $dsl + * @param array $arguments + * + * @throws QueryBuilderException + * + * @return Facade + */ + public function __call($dsl, array $arguments) + { + if (false === isset($this->_facades[$dsl])) { + throw new QueryBuilderException('DSL "'.$dsl.'" not supported'); + } + + return $this->_facades[$dsl]; + } + + /** + * Adds a new DSL object. + * + * @param DSL $dsl + */ + public function addDSL(DSL $dsl) + { + $this->_facades[$dsl->getType()] = new Facade($dsl, $this->_version); + } + + /* + * convenience methods + */ + + /** + * Query DSL. + * + * @return DSL\Query + */ + public function query() + { + return $this->_facades[DSL::TYPE_QUERY]; + } + + /** + * Filter DSL. + * + * @return DSL\Filter + */ + public function filter() + { + return $this->_facades[DSL::TYPE_FILTER]; + } + + /** + * Aggregation DSL. + * + * @return DSL\Aggregation + */ + public function aggregation() + { + return $this->_facades[DSL::TYPE_AGGREGATION]; + } + + /** + * Suggest DSL. + * + * @return DSL\Suggest + */ + public function suggest() + { + return $this->_facades[DSL::TYPE_SUGGEST]; + } +} |