Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
 {
     if (!$this->filtersSet && $this->hasReference('filter_query')) {
         /** @var BuilderInterface $filter */
         $filter = $this->getReference('filter_query');
         $this->addToBool($filter, BoolQuery::FILTER);
         $this->filtersSet = true;
     }
     if (!$this->bool) {
         return null;
     }
     return $this->bool->toArray();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
 /**
  * Test if simplified structure is returned in case single MUST query given.
  */
 public function testSingleMust()
 {
     $bool = new BoolQuery();
     $bool->add(new TermQuery('key2', 'value2'), BoolQuery::MUST);
     $expected = ['term' => ['key2' => 'value2']];
     $this->assertEquals($expected, $bool->toArray());
 }
Ejemplo n.º 4
0
 /**
  * Tests toArray() method.
  */
 public function testBoolToArray()
 {
     $bool = new BoolQuery();
     $bool->add(new TermQuery('key1', 'value1'), BoolQuery::SHOULD);
     $bool->add(new TermQuery('key2', 'value2'), BoolQuery::MUST);
     $bool->add(new TermQuery('key3', 'value3'), BoolQuery::MUST_NOT);
     $expected = ['should' => [['term' => ['key1' => 'value1']]], 'must' => [['term' => ['key2' => 'value2']]], 'must_not' => [['term' => ['key3' => 'value3']]]];
     $this->assertEquals($expected, $bool->toArray());
 }