Example #1
0
 public function testAddQueriesWithConfig()
 {
     $facetQuery1 = new Query();
     $facetQuery1->setKey('k1');
     $facetQuery1->setQuery('category:1');
     $facetQuery1->addExcludes(array('fq1', 'fq2'));
     $facetQuery2 = new Query();
     $facetQuery2->setKey('k2');
     $facetQuery2->setQuery('category:2');
     $facetQueries = array('k1' => $facetQuery1, 'k2' => $facetQuery2);
     $config = array(array('key' => 'k1', 'query' => 'category:1', 'exclude' => array('fq1', 'fq2')), 'k2' => array('query' => 'category:2'));
     $this->facet->addQueries($config);
     $this->assertEquals($facetQueries, $this->facet->getQueries());
 }
Example #2
0
 /**
  * Add a facetquery
  *
  * Supports a facetquery instance or a config array, in that case a new
  * facetquery instance wil be created based on the options.
  *
  * @throws InvalidArgumentException
  * @param  Query|array              $facetQuery
  * @return self                     Provides fluent interface
  */
 public function addQuery($facetQuery)
 {
     if (is_array($facetQuery)) {
         $facetQuery = new Query($facetQuery);
     }
     $key = $facetQuery->getKey();
     if (0 === strlen($key)) {
         throw new InvalidArgumentException('A facetquery must have a key value');
     }
     if (array_key_exists($key, $this->facetQueries)) {
         throw new InvalidArgumentException('A query must have a unique key value within a multiquery facet');
     }
     // forward shared excludes
     $facetQuery->addExcludes($this->getExcludes());
     $this->facetQueries[$key] = $facetQuery;
     return $this;
 }