public function testBoolFilter()
 {
     $index = $this->_createIndex('bool_filter_test');
     $type = $index->getType('book');
     //index some test data
     $type->addDocument(new \Elastica\Document(1, array('author' => 'Michael Shermer', 'title' => 'The Believing Brain', 'publisher' => 'Robinson')));
     $type->addDocument(new \Elastica\Document(2, array('author' => 'Jared Diamond', 'title' => 'Guns, Germs and Steel', 'publisher' => 'Vintage')));
     $type->addDocument(new \Elastica\Document(3, array('author' => 'Jared Diamond', 'title' => 'Collapse', 'publisher' => 'Penguin')));
     $type->addDocument(new \Elastica\Document(4, array('author' => 'Richard Dawkins', 'title' => 'The Selfish Gene', 'publisher' => 'OUP Oxford')));
     $type->addDocument(new \Elastica\Document(5, array('author' => 'Anthony Burges', 'title' => 'A Clockwork Orange', 'publisher' => 'Penguin')));
     $index->refresh();
     //use the terms lookup feature to query for some data
     //build query
     //must
     //  should
     //      author = jared
     //      author = richard
     //  must_not
     //      publisher = penguin
     //construct the query
     $query = new Query();
     $mainBoolFilter = new Bool();
     $shouldFilter = new Bool();
     $authorFilter1 = new Term();
     $authorFilter1->setTerm('author', 'jared');
     $authorFilter2 = new Term();
     $authorFilter2->setTerm('author', 'richard');
     $shouldFilter->addShould(array($authorFilter1, $authorFilter2));
     $mustNotFilter = new Bool();
     $publisherFilter = new Term();
     $publisherFilter->setTerm('publisher', 'penguin');
     $mustNotFilter->addMustNot($publisherFilter);
     $mainBoolFilter->addMust(array($shouldFilter, $mustNotFilter));
     $query->setFilter($mainBoolFilter);
     //execute the query
     $results = $index->search($query);
     //check the number of results
     $this->assertEquals($results->count(), 2, 'Bool filter with child Bool filters: number of results check');
     //count compare the id's
     $ids = array();
     /** @var \Elastica\Result $result **/
     foreach ($results as $result) {
         $ids[] = $result->getId();
     }
     $this->assertEquals($ids, array("2", "4"), 'Bool filter with child Bool filters: result ID check');
     $index->delete();
 }
 /**
  * Builds an or between many categories that the page could be in.
  * @param string[] $categories categories to match
  * @return \Elastica\Filter\Bool|null A null return value means all values are filtered
  *  and an empty result set should be returned.
  */
 public function matchPageCategories($categories)
 {
     $filter = new \Elastica\Filter\Bool();
     $ids = array();
     $names = array();
     foreach ($categories as $category) {
         if (substr($category, 0, 3) === 'id:') {
             $id = substr($category, 3);
             if (ctype_digit($id)) {
                 $ids[] = $id;
             }
         } else {
             $names[] = $category;
         }
     }
     foreach (Title::newFromIds($ids) as $title) {
         $names[] = $title->getText();
     }
     if (!$names) {
         return null;
     }
     foreach ($names as $name) {
         $filter->addShould($this->matchPage('category.lowercase_keyword', $name));
     }
     return $filter;
 }