Exemple #1
0
 public function testSetFacets()
 {
     $this->_field->clearFacets();
     $this->_field->addFacets(array('facet1', 'facet2'));
     $this->_field->setFacets(array('facet3', 'facet4'));
     $this->assertEquals(array('facet3', 'facet4'), $this->_field->getFacets());
 }
Exemple #2
0
 public function testSetFields()
 {
     $f1 = new Solarium_Query_Select_Component_Stats_Field();
     $f1->setKey('f1');
     $f2 = new Solarium_Query_Select_Component_Stats_Field();
     $f2->setKey('f2');
     $fields = array($f1, $f2);
     $this->_stats->addFields($fields);
     $f3 = new Solarium_Query_Select_Component_Stats_Field();
     $f3->setKey('f3');
     $f4 = new Solarium_Query_Select_Component_Stats_Field();
     $f4->setKey('f4');
     $fields2 = array('f3' => $f3, 'f4' => $f4);
     $this->_stats->setFields($fields2);
     $this->assertEquals($fields2, $this->_stats->getFields());
 }
Exemple #3
0
 /**
  * Add a field
  *
  * Supports a field instance or a config array, in that case a new
  * field instance wil be created based on the options.
  *
  * @param Solarium_Query_Select_Component_Stats_Field|array $field
  * @return Solarium_Query_Select_Component_Stats Provides fluent interface
  */
 public function addField($field)
 {
     if (is_array($field)) {
         $field = new Solarium_Query_Select_Component_Stats_Field($field);
     }
     $key = $field->getKey();
     if (0 === strlen($key)) {
         throw new Solarium_Exception('A field must have a key value');
     }
     //double add calls for the same field are ignored, but non-unique keys cause an exception
     //@todo add trigger_error with a notice for double add calls?
     if (array_key_exists($key, $this->_fields) && $this->_fields[$key] !== $field) {
         throw new Solarium_Exception('A field must have a unique key value');
     } else {
         $this->_fields[$key] = $field;
     }
     return $this;
 }