예제 #1
0
 public function testAddBoostQueryWithUsedKey()
 {
     $bq1 = new BoostQuery();
     $bq1->setKey('bq1')->setQuery('category:1');
     $bq2 = new BoostQuery();
     $bq2->setKey('bq1')->setQuery('category:2');
     $this->disMax->addBoostQuery($bq1);
     $this->setExpectedException('Solarium\\Exception\\InvalidArgumentException');
     $this->disMax->addBoostQuery($bq2);
 }
예제 #2
0
 public function testConfigMode()
 {
     $fq = new BoostQuery(array('key' => 'k1', 'query' => 'id:[10 TO 20]'));
     $this->assertEquals('k1', $fq->getKey());
     $this->assertEquals('id:[10 TO 20]', $fq->getQuery());
 }
예제 #3
0
 /**
  * Add a boost query.
  *
  * Supports a boostquery instance or a config array, in that case a new
  * boostquery instance wil be created based on the options.
  *
  * @throws InvalidArgumentException
  *
  * @param BoostQuery|array $boostQuery
  *
  * @return self Provides fluent interface
  */
 public function addBoostQuery($boostQuery)
 {
     if (is_array($boostQuery)) {
         $boostQuery = new BoostQuery($boostQuery);
     }
     $key = $boostQuery->getKey();
     if (0 === strlen($key)) {
         throw new InvalidArgumentException('A boostquery must have a key value');
     }
     //double add calls for the same BQ are ignored, but non-unique keys cause an exception
     if (array_key_exists($key, $this->boostQueries) && $this->boostQueries[$key] !== $boostQuery) {
         throw new InvalidArgumentException('A boostquery must have a unique key value within a query');
     } else {
         $this->boostQueries[$key] = $boostQuery;
     }
     return $this;
 }