コード例 #1
0
 /**
  * Tests isRelevant method with 2 queries.
  */
 public function testBoolIsRelevantWithTwoQuery()
 {
     $bool = new BoolQuery();
     $this->assertFalse($bool->isRelevant());
     $bool->add(new TermQuery('acme', 'foo'));
     $bool->add(new TermQuery('bar', 'go'));
     $this->assertTrue($bool->isRelevant());
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
 {
     if ($this->hasReference('filtered_query')) {
         /** @var FilteredQuery $filteredQuery */
         $filteredQuery = $this->getReference('filtered_query');
         $this->add($filteredQuery);
     }
     if (!$this->bool) {
         return null;
     }
     $queryArray = $this->bool->toArray();
     if ($this->bool->isRelevant()) {
         $queryArray = [$this->bool->getType() => $queryArray];
     }
     return $queryArray;
 }