{@inheritdoc}
@throws Exception\QueryBuildingException
175765
public function moreLikeThis(array $like, array $fields = [], array $options = []): void
    {
        $moreLikeThis = $options;
        $moreLikeThis['like'] = $like;

        if (!empty($fields)) {
            $moreLikeThis['fields'] = $fields;
        }

        $this->appendAtPath('query.bool.filter.bool.must', ['more_like_this' => $moreLikeThis]);
    }
889498
public static function buildWheres(QueryInterface $query, array $conditions, $allowNulls = true)
    {
        foreach ($conditions as $key => $value) {
            // NULL
            if ($value === null && $allowNulls) {
                $query->where($query->format('%n IS NULL', $key));
            } elseif ($value instanceof Compare) {
                // If using Compare class, we convert it to string.
                $query->where((string) static::buildCompare($key, $value, $query));
            } elseif (is_numeric($key)) {
                // If key is numeric, just send value to query where.
                $query->where($value);
            } elseif (is_array($value) || is_object($value)) {
                // If is array or object, we use "IN" condition.
                if ($value instanceof \Traversable) {
                    $value = iterator_to_array($value);
                } elseif (is_object($value)) {
                    $value = get_object_vars($value);
                }

                $value = array_map([$query, 'quote'], $value);

                $query->where($query->quoteName($key) . new QueryElement('IN ()', $value, ','));
            } else {
                // Otherwise, we use equal condition.
                $query->where($query->format('%n = %q', $key, $value));
            }
        }

        return $query;
    }
773187
public function getQuery()
    {
        $idField = $this->documentKey;

        if ($idField == null) {
            throw new QueryException('id should not be null');
        }

        $this->setQuery(sprintf('id:%s', $idField));

        return parent::getQuery();
    }
972415
public static function execute(UnionQueryProvider $queryProvider, $buildDepth=BuildDepth::SINGLE, $orderby=null, PagingInfo $pagingInfo=null) {
    $cache = ObjectFactory::getInstance('dynamicCache');
    $cacheSection = str_replace('\\', '.', __CLASS__);

    $queryIds = $queryProvider->getIds();
    $numQueries = sizeof($queryIds);

    // get cache key for stored offsets of previous page
    $pagingInfo = $pagingInfo ?: new PagingInfo(PagingInfo::SIZE_INFINITE);
    $page = $pagingInfo->getPage();
    $prevPage = $page > 1 ? $page-1 : 1;
    $prevPagingInfo = new PagingInfo($pagingInfo->getPageSize(), true);
    $prevPagingInfo->setPage($prevPage);
    $prevCacheKey = self::getCacheKey($queryIds, $buildDepth, $orderby, $prevPagingInfo);

    // get offsets
    if ($page == 1) {
      $offsets = array_fill(0, $numQueries, 0);
    }
    else {
      if ($cache->exists($cacheSection, $prevCacheKey)) {
        $offsets = $cache->get($cacheSection, $prevCacheKey);
      }
      else {
        // previous offsets must be generated by loading the pages for pages other than first
        for ($i=1; $i<$page; $i++) {
          $tmpPagingInfo = new PagingInfo($pagingInfo->getPageSize(), true);
          $tmpPagingInfo->setPage($i);
          $tmpCacheKey = self::getCacheKey($queryIds, $buildDepth, $orderby, $tmpPagingInfo);
          if (!$cache->exists($cacheSection, $tmpCacheKey)) {
            self::execute($queryProvider, $buildDepth, $orderby, $tmpPagingInfo);
          }
          $offsets = $cache->get($cacheSection, $tmpCacheKey);
        }
      }
    }

    $tmpResult = [];
    $total = 0;
    for ($i=0, $countI=$numQueries; $i<$countI; $i++) {
      // collect n objects from each query
      $queryId = $queryIds[$i];

      // set paging info
      $tmpPagingInfo = new PagingInfo($pagingInfo->getPageSize(), false);
      $tmpPagingInfo->setOffset($offsets[$i]);

      $objects = $queryProvider->execute($queryId, $buildDepth, $orderby, $tmpPagingInfo);
      foreach ($objects as $object) {
        $object->setProperty('queryId', $queryId);
      }
      $tmpResult = array_merge($tmpResult, $objects);
      $total += $tmpPagingInfo->getTotalCount();
    }
    $pagingInfo->setTotalCount($total);

    // sort
    if ($orderby != null) {
      $comparator = new ObjectComparator($orderby);
      usort($tmpResult, [$comparator, 'compare']);
    }

    // truncate
    $result = array_slice($tmpResult, 0, $pagingInfo->getPageSize());

    // update offsets
    $counts = array_fill_keys($queryIds, 0);
    for ($i=0, $count=sizeof($result); $i<$count; $i++) {
      $counts[$result[$i]->getProperty('queryId')]++;
    }
    for ($i=0, $count=$numQueries; $i<$count; $i++) {
      $offsets[$i] += $counts[$queryIds[$i]];
    }
    $cacheKey = self::getCacheKey($queryIds, $buildDepth, $orderby, $pagingInfo);
    $cache->put($cacheSection, $cacheKey, $offsets);
    return $result;
  }
983085
protected function assembleQuery() {
		if (empty($this->query)) {
			if ($this->queryRaw === null) {
				return '';
			}
			
			return $this->queryRaw;
		}
		
		return '?' . http_build_query($this->query);
	}
917115
public function apply(ColumnInterface $column, Builder $query, $queryString, $queryParams)
    {
        $queryString = $this->parseValue($queryString);

        if (($metaInstance = $column->getMetaData()) instanceof ColumnMetaInterface) {
            if (method_exists($metaInstance, 'onFilterSearch')) {
                $metaInstance->onFilterSearch($column, $query, $queryString, $queryParams);

                return;
            }
        }

        if (is_callable($callback = $column->getFilterCallback())) {
            $callback($column, $query, $queryString, $queryParams);

            return;
        }

        if (is_callable($callback = $this->getCallback())) {
            $callback($column, $query, $queryString, $queryParams);

            return;
        }

        if (empty($queryString) && strlen($queryString) == 0) {
            return;
        }

        if (is_null($name = $this->getColumnName())) {
            $name = $column->getName();
        }

        if (strpos($name, '.') !== false) {
            $parts = explode('.', $name);
            $fieldName = array_pop($parts);
            $relationName = implode('.', $parts);

            $query->whereHas($relationName, function ($q) use ($queryString, $fieldName) {
                $this->buildQuery($q, $fieldName, $queryString);
            });
        } else {
            $this->buildQuery($query, $name, $queryString);
        }
    }
209762
public function newQuery() : QueryBuilder
    {
        $model = $this->container->make($this->getModelName());

        if (!$model instanceof Model) {
            throw new RepositoryException("Class {$this->model()} must be an instance of " . Model::class);
        }

        return $model->newQuery();
    }
1310996
protected function createQueryBuilder($joins = null)
    {
        $this->queryBuilder = $this->em->createQueryBuilder()
            ->from($this->entityName, $this->encodeAlias($this->entityName));

        $this->assignJoins($this->queryBuilder, $joins);

        if (null !== $this->ids) {
            $this->in($this->idField, !empty($this->ids) ? $this->ids : [null]);
        }

        if (null !== $this->excludedIds && !empty($this->excludedIds)) {
            $this->notIn($this->idField, $this->excludedIds);
        }

        // set expressions
        if (!empty($this->expressions)) {
            foreach ($this->expressions as $expression) {
                $this->queryBuilder->andWhere('(' . $expression->getStatement($this->queryBuilder) . ')');
            }
        }

        $this->assignGroupBy($this->queryBuilder);

        if (null !== $this->search) {
            $searchParts = [];
            foreach ($this->searchFields as $searchField) {
                $searchParts[] = $searchField->getSearch();
            }

            $this->queryBuilder->andWhere('(' . implode(' OR ', $searchParts) . ')');
            $this->queryBuilder->setParameter('search', '%' . str_replace('*', '%', $this->search) . '%');
        }

        return $this->queryBuilder;
    }
4452
public function process(QueryInterface $query)
    {
        if (!$query instanceof ShowQuery || $query->getObject() !== ShowQuery::EXPRESSION_CREATE_TABLE) {
            return null;
        }

        $table = $query->getCreateObjectExpression(ShowQuery::EXPRESSION_CREATE_TABLE);

        if (!$table) {
            throw new Exception('Table missing.');
        }

        $tablet = $this->tablet->getTablet();
        $schemaCmd = new GetSchema($tablet->getAlias());
        /* @var $result GetSchemaResult */
        $result = $this->client->executeCommand($schemaCmd);

        return new CreateTable($result, $table);
    }
929963
public function buildQuery($query = null)
    {
        if (null === $query) {
            $query = $this->query;
        }

        $sql = "SELECT ";
        if (isset($query['distinct']) && $query['distinct']) {
            $sql .= 'DISTINCT ';
        }
        $sql .= isset($query['select']) ? $query['select'] : '*';

        if (!isset($query['from'])) {
            return false;
        }

        $sql .= "\nFROM " . $query['from'];
        if (isset($query['join'])) {
            $sql .= "\n" . (is_array($query['join']) ? implode("\n", $query['join']) : $query['join']);
        }
        if (isset($query['where']) && $query['where'] !== '') {
            $sql .= "\nWHERE " . $query['where'];
        }
        if (isset($query['group'])) {
            $sql .= "\nGROUP BY " . $query['group'];
            if (isset($query['having'])) {
                $sql .= "\nHAVING " . $query['having'];
            }
        }
        if (isset($query['order'])) {
            $sql .= "\n ORDER BY " . $query['order'];
        }
        $limit = isset($query['limit']) ? $query['limit'] : 0;
        $offset = isset($query['offset']) ? $query['offset'] : 0;
        $sql = $this->db->buildLimitOffset($sql, $limit, $offset);

        if (isset($query['union'])) {
            $sql .= "\n" . (is_array($query['union']) ? implode("\n", $query['union']) : $query['union']);
        }

        return $sql;
    }
652337
protected function executeQuery()
    {
        if (empty($this->queryString)) {
            return $this->builder->execute();
        }

        return $this->connection->executeQuery($this->queryString, $this->queryParams);
    }
1023759
public function exec($query)
    {
        try {
            $this->connection->exec($query);
        } catch (DBALException $e) {
            throw new QueryException($e->getMessage(), $e->getCode(), $e);
        }
    }
1347505
protected function buildQuery(array $queryParams = [])
    {
        $auth = [
            'appId' => $this->config['appId'],
            'appKey' => $this->config['appKey'],
        ];

        $queryParams = array_merge($auth, $queryParams);

        if (isset($queryParams['extendedOptions'])) {
            $extendedOptions = $queryParams['extendedOptions'];
        } else {
            $extendedOptions = [];
        }

        if (!is_array($extendedOptions)) {
            $extendedOptions = [$extendedOptions];
        }

        if ($this->config['use_http_errors'] &&
            !in_array('useHTTPErrors', $extendedOptions)
        ) {
            $extendedOptions[] = 'useHTTPErrors';
        }

        $queryParams['extendedOptions'] = implode('+', $extendedOptions);

        return $queryParams;
    }
630061
private function queryJoinBuilder($query, $relation)
    {
        $relatedTable = $relation->getRelated()->getTable();
        $parentTable  = $relation->getParent()->getTable();

        if ($parentTable === $relatedTable) {
            $query       = $query->from($parentTable.' as parent_'.$parentTable);
            $parentTable = 'parent_'.$parentTable;
            $relation->getParent()->setTable($parentTable);
        }

        if ($relation instanceof HasOne) {
            $relatedPrimaryKey = $relation->getQualifiedForeignKeyName();
            $parentPrimaryKey  = $relation->getQualifiedParentKeyName();
        } elseif ($relation instanceof BelongsTo) {
            $relatedPrimaryKey = $relation->getQualifiedOwnerKeyName();
            $parentPrimaryKey  = $relation->getQualifiedForeignKeyName();
        } else {
            throw new \Exception();
        }

        return $this->formJoin($query, $parentTable, $relatedTable, $parentPrimaryKey, $relatedPrimaryKey);
    }
500872
public function select( $query, $bindings = [] )
	{
		$query = $this->bind_params( $query, $bindings );

		$result = $this->db->get_results( $query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return $result;
	}
702980
public function build()
    {
        $query = $this->delegate->build();
        $this->utilityRegistry->addUtility(AdsUtility::REPORT_QUERY_BUILDER);
        return $query;
    }
1299295
public function build(): QuerySelectorRequest
	{
		$instance = new QuerySelectorRequest();
		if ($this->nodeId === null) {
			throw new BuilderException('Property [nodeId] is required.');
		}
		$instance->nodeId = $this->nodeId;
		if ($this->selector === null) {
			throw new BuilderException('Property [selector] is required.');
		}
		$instance->selector = $this->selector;
		return $instance;
	}