@param Query $query
@param bool  $isUnionAll

@return Query
331449
public function union(self $query, $isUnionAll = false)
    {
        $this->queryUnion = $query;
        $this->queryUnionAll = $isUnionAll;

        return $this;
    }
208820
private function buildQuery(Query $query): ContentfulQuery
    {
        $contentfulQuery = new ContentfulQuery();

        if (trim($query->getParameter('search_text')->getValue() ?? '') !== '') {
            $contentfulQuery->where('query', $query->getParameter('search_text')->getValue());
        }

        $optionsArray = explode('|', $query->getParameter('client')->getValue());
        if (array_key_exists(1, $optionsArray)) {
            $contentfulQuery->setContentType($optionsArray[1]);
        }

        $sortType = $query->getParameter('sort_type')->getValue();
        if ($sortType !== null) {
            $contentfulQuery->orderBy($sortType, $query->getParameter('sort_direction')->getValue());
        }

        return $contentfulQuery;
    }
1124389
private function buildSubclauseWithNull($subclause, Builder $query, $isNotNull = false)
    {
        if ($isNotNull === true) {
            return $query->whereNotNull($subclause['to_value_column']);
        }

        return $query->whereNull($subclause['to_value_column']);
    }
692110
public function apply(Builder $query, $or = false)
    {
        $field_alias = $this->field_alias;

        if(is_array($this->value))
        {
            if($or)
            {
                $query->orWhereIn($field_alias, $this->value);
            }
            else
            {
                $query->whereIn($field_alias, $this->value);
            }
        }
        else
        {
            if($or)
            {
                $query->orWhere($field_alias, '=', $this->value);
            }
            else
            {
                $query->where($field_alias, '=', $this->value);
            }
        }
    }
812864
public function withQuery(string $query): URI
    {
        $result = clone $this;
        $result->query = $this->filterQuery($query);

        return $result;
    }
974813
public function withQuery($query)
    {
        if (!is_string($query) && !method_exists($query, '__toString')) {
            throw new \InvalidArgumentException('Query string must be a string');
        }
        $query = (string) $query;
        if (strpos($query, '?') === 0) {
            $query = substr($query, 1);
        }
        $query = $this->filterQueryAndFragment($query);

        $new = clone $this;
        $new->query = $query;

        return $new;
    }
1118807
public function union($query, $all = false)
    {
        if ($query instanceof Closure) {
            call_user_func($query, $query = $this->newQuery());
        }

        $this->unions[] = compact('query', 'all');

        return $this->mergeBindings($query);
    }
381366
public function select(Query $query)
    {
        $options = $query->getOptions();

        $where = $this->parseWhere($query, $options['where']);
        $query = new MongoQuery($where, $options);

        $this->log('find', $where, $options);

        return $query;
    }
217079
protected function buildOperationQuery(
            Queries\IScope $scope,
            Queries\IOperation $operation
    ) {
        return new Queries\OperationQuery($scope, $operation);
    }
401323
public function when($condition, $query, $otherwise = null)
    {
        if ($condition instanceof \Closure) {
            $condition = $condition($this);
        }

        if ($condition) {
            if ($query instanceof \Closure) {
                $query($this, $condition);
            } elseif (is_array($query)) {
                $this->where($query);
            }
        } elseif ($otherwise) {
            if ($otherwise instanceof \Closure) {
                $otherwise($this, $condition);
            } elseif (is_array($otherwise)) {
                $this->where($otherwise);
            }
        }

        return $this;
    }
832705
public function createQuery(Query $query): Query
    {
        $dbQuery = $this->connection->createQueryBuilder()
            ->insert('ngbm_collection_query')
            ->values(
                [
                    'id' => ':id',
                    'status' => ':status',
                    'collection_id' => ':collection_id',
                    'type' => ':type',
                ]
            )
            ->setValue(
                'id',
                $query->id !== null ?
                    (int) $query->id :
                    $this->connectionHelper->getAutoIncrementValue('ngbm_collection_query')
            )
            ->setParameter('status', $query->status, Type::INTEGER)
            ->setParameter('collection_id', $query->collectionId, Type::INTEGER)
            ->setParameter('type', $query->type, Type::STRING);

        $dbQuery->execute();

        $query->id = $query->id ?? (int) $this->connectionHelper->lastInsertId('ngbm_collection_query');

        return $query;
    }
384782
public function redirect($url, $query = [], $is_query_string = false)
	{
		if (!empty($query)) {
			if ($is_query_string && is_array($query)) {
				# home/people?lastname=smith
				$url = rtrim($url, DIRECTORY_SEPARATOR) . '?' . http_build_query($query);
			} elseif (is_array($query)) {
				# home/people/1,2
				$url = rtrim($url, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . join(',', $query);
			} else {
				# home/people/1
				$url = rtrim($url, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . urlencode($query);
			}
		}

		if (!preg_match('/^http/', $url)) {
			// Internal redirect
			$url = DIRECTORY_SEPARATOR . trim($url, DIRECTORY_SEPARATOR);
			$url = $this->template->uri($url);
		}

		/**
		 * You MUST call session_write_close() before performing a redirect to ensure the session is written,
		 * otherwise it might not happen quickly enough to save your session changes.
		 */
		session_write_close();

		$response = new RedirectResponse($url);
		$response->send();
	}
1363625
protected static function unionQueriesToOne($queries)
    {
        if (count($queries) === 0) {
            throw new Exception(Module::t('app', 'Nothing to union'));
        }

        $query = array_reduce(
            $queries,
            function ($query, $item) {
                /**
                 * @var $query Query
                 */
                if ($query === null) {
                    $query = $item;
                } else {
                    $query->union($item);
                }
                return $query;
            }
        );

        return $query;
    }
190303
public function findSlugged(Query $query, array $options)
    {
        if (!isset($options['slug'])) {
            throw new InvalidArgumentException('The `slug` key is required by the `slugged` finder.');
        }

        return $query->where([
            $this->_table->aliasField($this->getConfig('field')) => $options['slug'],
        ]);
    }
373389
public function apply(Builder $query, $or = false)
    {
        $field_alias = $this->field_alias;

        if($or)
        {
            $query->orWhereBetween($field_alias, [$this->value_min, $this->value_max]);
        }
        else
        {
            $query->whereBetween($field_alias, [$this->value_min, $this->value_max]);
        }
    }
151560
public function findSlugged(Query $query, array $options) {
		if (empty($options['slug'])) {
			throw new InvalidArgumentException("The 'slug' key is required for find('slugged')");
		}

		return $query->where([$this->_config['field'] => $options['slug']]);
	}
164406
public static function mergeQuery($uri, $query)
    {
        return $uri->withQuery((string) (new Query(self::filterUri($uri)->getQuery()))->merge($query));
    }