From 5ea69c0b2427cb0a82611eef81fef1e0d5174c2c Mon Sep 17 00:00:00 2001
From: Martynas Sudintas <martynas.sudintas@ongr.io>
Date: Fri, 15 Jan 2016 16:05:14 +0200
Subject: [PATCH] do not set filtered query into query endpoint during
 normalization

---
 src/SearchEndpoint/QueryEndpoint.php | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/SearchEndpoint/QueryEndpoint.php b/src/SearchEndpoint/QueryEndpoint.php
index 9b610b5..8caf651 100644
--- a/src/SearchEndpoint/QueryEndpoint.php
+++ b/src/SearchEndpoint/QueryEndpoint.php
@@ -40,20 +40,24 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI
      */
     public function normalize(NormalizerInterface $normalizer, $format = null, array $context = [])
     {
+        $query = $this->getBool();
+
         if ($this->hasReference('filtered_query')) {
             /** @var FilteredQuery $filteredQuery */
             $filteredQuery = $this->getReference('filtered_query');
-            $this->add($filteredQuery);
+
+            if ($query) {
+                $filteredQuery->setQuery($query);
+            }
+
+            $query = $filteredQuery;
         }
 
-        if (!$this->bool) {
+        if (!$query) {
             return null;
         }
 
-        $queryArray = $this->bool->toArray();
-        $queryArray = [$this->bool->getType() => $queryArray];
-
-        return $queryArray;
+        return [$query->getType() => $query->toArray()];
     }
 
     /**
-- 
GitLab