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());
 }
Exemplo n.º 4
0
 /**
  * @group unit
  */
 public function testToArray()
 {
     $orFilter = new BoolOr();
     $filter1 = new Ids();
     $filter1->setIds('1');
     $filter2 = new Ids();
     $filter2->setIds('2');
     $orFilter->addFilter($filter1);
     $orFilter->addFilter($filter2);
     $expectedArray = array('or' => array($filter1->toArray(), $filter2->toArray()));
     $this->assertEquals($expectedArray, $orFilter->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());
 }
Exemplo n.º 6
0
 /**
  * @group functional
  */
 public function testSetCache()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     $type->addDocuments(array(new Document(1, array('name' => 'hello world')), new Document(2, array('name' => 'nicolas ruflin')), new Document(3, array('name' => 'ruflin'))));
     $and = new BoolAnd();
     $idsFilter1 = new Ids();
     $idsFilter1->setIds(1);
     $idsFilter2 = new Ids();
     $idsFilter2->setIds(1);
     $and->addFilter($idsFilter1);
     $and->addFilter($idsFilter2);
     $index->refresh();
     $and->setCached(true);
     $resultSet = $type->search($and);
     $this->assertEquals(1, $resultSet->count());
 }
Exemplo n.º 7
0
 /**
  * @group unit
  */
 public function testAddType()
 {
     $type = $this->_getClient()->getIndex('indexname')->getType('typename');
     $filter = new Ids();
     $filter->addType('foo');
     $this->assertEquals(array('foo'), $filter->getParam('type'));
     $filter->addType($type);
     $this->assertEquals(array('foo', $type->getName()), $filter->getParam('type'));
     $returnValue = $filter->addType('bar');
     $this->assertInstanceOf('Elastica\\Filter\\Ids', $returnValue);
 }
 public function testSetTypeArraySearchSingle()
 {
     $filter = new Ids();
     $filter->setIds('4');
     $filter->setType(array('helloworld1', 'helloworld2'));
     $query = Query::create($filter);
     $resultSet = $this->_index->search($query);
     $this->assertEquals(2, $resultSet->count());
 }