Exemplo n.º 1
0
 /**
  * @return array
  */
 public function getTestToArrayData()
 {
     $this->hideDeprecated();
     $out = array();
     // case #0
     $mainBool = new BoolFilter();
     $idsFilter1 = new Ids();
     $idsFilter1->setIds(1);
     $idsFilter2 = new Ids();
     $idsFilter2->setIds(2);
     $idsFilter3 = new Ids();
     $idsFilter3->setIds(3);
     $childBool = new BoolFilter();
     $childBool->addShould(array($idsFilter1, $idsFilter2));
     $mainBool->addShould(array($childBool, $idsFilter3));
     $expectedArray = array('bool' => array('should' => array(array(array('bool' => array('should' => array(array($idsFilter1->toArray(), $idsFilter2->toArray())))), $idsFilter3->toArray()))));
     $out[] = array($mainBool, $expectedArray);
     // case #1 _cache parameter should be supported
     $bool = new BoolFilter();
     $terms = new Terms('field1', array('value1', 'value2'));
     $termsNot = new Terms('field2', array('value1', 'value2'));
     $bool->addMust($terms);
     $bool->addMustNot($termsNot);
     $bool->setCached(true);
     $bool->setCacheKey('my-cache-key');
     $expected = array('bool' => array('must' => array($terms->toArray()), 'must_not' => array($termsNot->toArray()), '_cache' => true, '_cache_key' => 'my-cache-key'));
     $out[] = array($bool, $expected);
     $this->showDeprecated();
     return $out;
 }
Exemplo n.º 2
0
 /**
  * @group unit
  */
 public function testConstruct()
 {
     $filter = new Ids();
     $filter->setIds(array(1));
     $query = new ConstantScore($filter);
     $expectedArray = array('constant_score' => array('filter' => $filter->toArray()));
     $this->assertEquals($expectedArray, $query->toArray());
 }
Exemplo n.º 3
0
 /**
  * @group unit
  */
 public function testToArray()
 {
     $idsFilter = new Ids();
     $idsFilter->setIds(12);
     $filter = new BoolNot($idsFilter);
     $expectedArray = array('not' => array('filter' => $idsFilter->toArray()));
     $this->assertEquals($expectedArray, $filter->toArray());
 }
 public function testToArray()
 {
     $mainBool = new Bool();
     $idsFilter1 = new Ids();
     $idsFilter1->setIds(1);
     $idsFilter2 = new Ids();
     $idsFilter2->setIds(2);
     $idsFilter3 = new Ids();
     $idsFilter3->setIds(3);
     $childBool = new Bool();
     $childBool->addShould(array($idsFilter1, $idsFilter2));
     $mainBool->addShould(array($childBool, $idsFilter3));
     $expectedArray = array('bool' => array('should' => array(array(array('bool' => array('should' => array(array($idsFilter1->toArray(), $idsFilter2->toArray())))), $idsFilter3->toArray()))));
     $this->assertEquals($expectedArray, $mainBool->toArray());
 }