Example #1
0
 /**
  * @group unit
  */
 public function testAddIndex()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('someindex');
     $filter = new Indices(new Term(array('color' => 'blue')), array());
     $filter->addIndex($index);
     $expected = array($index->getName());
     $this->assertEquals($expected, $filter->getParam('indices'));
     $filter->addIndex('foo');
     $expected = array($index->getName(), 'foo');
     $this->assertEquals($expected, $filter->getParam('indices'));
     $returnValue = $filter->addIndex('bar');
     $this->assertInstanceOf('Elastica\\Filter\\Indices', $returnValue);
 }
Example #2
0
 public function testIndicesFilter()
 {
     $filter = new Indices(new BoolNot(new Term(array("color" => "blue"))), array($this->_index1->getName()));
     $filter->setNoMatchFilter(new BoolNot(new Term(array("color" => "yellow"))));
     $query = new Query();
     $query->setPostFilter($filter);
     // search over the alias
     $index = $this->_getClient()->getIndex("indices_filter");
     $results = $index->search($query);
     // ensure that the proper docs have been filtered out for each index
     $this->assertEquals(5, $results->count());
     foreach ($results->getResults() as $result) {
         $data = $result->getData();
         $color = $data["color"];
         if ($result->getIndex() == $this->_index1->getName()) {
             $this->assertNotEquals("blue", $color);
         } else {
             $this->assertNotEquals("yellow", $color);
         }
     }
 }