* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @link http://www.solarium-project.org/ * * @package Solarium * @subpackage Query */ /** * Filterquery * * @link http://wiki.apache.org/solr/CommonQueryParameters#fq * * @package Solarium * @subpackage Query */ class Solarium_Query_Select_FilterQuery extends Solarium_Configurable { /** * Tags for this filterquery * * @var array */ protected $_tags = array(); /** * Query * * @var string */ protected $_query; /** * Initialize options * * @return void */ protected function _init() { foreach ($this->_options AS $name => $value) { switch ($name) { case 'tag': if(!is_array($value)) $value = array($value); $this->addTags($value); break; case 'key': $this->setKey($value); break; case 'query': $this->setQuery($value); break; } } } /** * Get key value * * @return string */ public function getKey() { return $this->getOption('key'); } /** * Set key value * * @param string $value * @return Solarium_Query_Select_FilterQuery Provides fluent interface */ public function setKey($value) { return $this->_setOption('key', $value); } /** * Set the query string * * This overwrites the current value * * @param string $query * @param array $bind Bind values for placeholders in the query string * @return Solarium_Query Provides fluent interface */ public function setQuery($query, $bind = null) { if (!is_null($bind)) { $helper = new Solarium_Query_Helper; $query = $helper->assemble($query, $bind); } $this->_query = trim($query); return $this; } /** * Get the query string * * @return string */ public function getQuery() { return $this->_query; } /** * Add a tag * * @param string $tag * @return Solarium_Query_Select_FilterQuery Provides fluent interface */ public function addTag($tag) { $this->_tags[$tag] = true; return $this; } /** * Add tags * * @param array $tags * @return Solarium_Query_Select_FilterQuery Provides fluent interface */ public function addTags($tags) { foreach ($tags AS $tag) { $this->addTag($tag); } return $this; } /** * Get all tagss * * @return array */ public function getTags() { return array_keys($this->_tags); } /** * Remove a tag * * @param string $tag * @return Solarium_Query_Select_FilterQuery Provides fluent interface */ public function removeTag($tag) { if (isset($this->_tags[$tag])) { unset($this->_tags[$tag]); } return $this; } /** * Remove all tags * * @return Solarium_Query_Select_FilterQuery Provides fluent interface */ public function clearTags() { $this->_tags = array(); return $this; } /** * Set multiple tags * * This overwrites any existing tags * * @param array $filterQueries * @return Solarium_Query_Select_FilterQuery Provides fluent interface */ public function setTags($filterQueries) { $this->clearTags(); return $this->addTags($filterQueries); } }