src/Sherlock/requests/SearchRequest.php
private function composeFinalQuery()
    {
        $finalQuery = array();

        if (isset($this->params['fields'])) {
            $finalQuery['fields'] = $this->params['fields'];
        }

        if (isset($this->params['query']) && $this->params['query'] instanceof components\QueryInterface) {
            $finalQuery['query'] = $this->params['query']->toArray();
        }

        if (isset($this->params['filter']) && $this->params['filter'] instanceof components\FilterInterface) {
            $finalQuery['filter'] = $this->params['filter']->toArray();
        }

        if (isset($this->params['facets'])) {
            $tFacets = array();
            foreach ($this->params['facets'] as $facet) {
                //@todo Investigate a better way of doing this
                //array_merge is supposedly slow when merging arrays of arrays
                if ($facet instanceof FacetInterface) {
                    $tFacets = array_merge($tFacets, $facet->toArray());
                }
            }
            $finalQuery['facets'] = $tFacets;
            unset($tFacets);
        }

        if (isset($this->params['highlight']) && $this->params['highlight'] instanceof components\HighlightInterface) {
            $finalQuery['highlight'] = $this->params['highlight']->toArray();
        }

        foreach (array('from', 'size', 'timeout', 'sort', 'min_score') as $key) {
            if (isset($this->params[$key])) {
                $finalQuery[$key] = $this->params[$key];
            }
        }

        $finalQuery = json_encode($finalQuery, true);

        return $finalQuery;
    }
private function composeFinalQuery()
    {
        $finalQuery = array();

        if (isset($this->params['fields'])) {
            $finalQuery['fields'] = $this->params['fields'];
        }

        if (isset($this->params['query']) && $this->params['query'] instanceof components\QueryInterface) {
            $finalQuery['query'] = $this->params['query']->toArray();
        }

        if (isset($this->params['filter']) && $this->params['filter'] instanceof components\FilterInterface) {
            $finalQuery['filter'] = $this->params['filter']->toArray();
        }

        if (isset($this->params['facets'])) {
            $tFacets = array();
            foreach ($this->params['facets'] as $facet) {
                //@todo Investigate a better way of doing this
                //array_merge is supposedly slow when merging arrays of arrays
                if ($facet instanceof FacetInterface) {
                    $tFacets = array_merge($tFacets, $facet->toArray());
                }
            }
            $finalQuery['facets'] = $tFacets;
            unset($tFacets);
        }

        if (isset($this->params['highlight']) && $this->params['highlight'] instanceof components\HighlightInterface) {
            $finalQuery['highlight'] = $this->params['highlight']->toArray();
        }

        foreach (array('from', 'size', 'timeout', 'sort', 'min_score') as $key) {
            if (isset($this->params[$key])) {
                $finalQuery[$key] = $this->params[$key];
            }
        }

        $finalQuery = json_encode($finalQuery, true);

        return $finalQuery;
    }
Composes the final query, aggregating together the queries, filters, facets and associated parameters

@return string
@throws \Sherlock\common\exceptions\RuntimeException