@param type $query

@return type
432599
public static function submit($query)
    {
        $object = static::exists($query);

        if (!$object) {
            $object = static::create($query);
            $object->store();
        }

        return $object;
    }
406281
public function getSearch($query, $type = null)
    {
        $uri = 'search';
        $uriData = [
            'q' => $query
        ];
        if ( $type ) { $uriData['type'] = $type; }

        try {
            $response = $this->_request(
                [
                    'uri' => $uri,
                    'type' => 'get',
                    'data' => $uriData
                ]
            );
        } catch (\Exception $e) {
            throw new InvalidException($e->getMessage());
        }

        return $response->getBody()->getContents();
    }
823444
protected function _where($query)
    {
        $link = null;
        $type_check = true;

        if ($query instanceof AnConfig) {
            $type_check = false;
            $query = $query->query;
        }

        $description = $query->getRepository()->getDescription();
        $clauses = array();
        if ($description->getInheritanceColumn() && $type_check) {
            $resource = $description->getInheritanceColumn()->resource->getAlias();
            //the table type column name
            $type_column_name = $resource.'.'.$description->getInheritanceColumn()->name;

            $scopes = AnConfig::unbox($query->instance_of);
            if (empty($scopes)) {
                $scopes = array($description);
            } else {
                if (!is_array($scopes)) {
                    $scopes = array($scopes);
                }
            }

            foreach ($scopes as $index => $scope) {
                $inheritance_type = $this->_inheritanceTree($scope);
                if (!empty($inheritance_type) && $inheritance_type != '%') {
                    $operator = substr($inheritance_type, -1) == '%' ? 'LIKE' : '=';
                    $scopes[$index] = $type_column_name.' '.$operator.' \''.$inheritance_type.'\'';
                } else {
                    unset($scopes[$index]);
                }
            }
            if (!empty($scopes)) {
                $clauses[] = '('.implode(' OR ', $scopes).')';
            }
        }

        if (!empty($query->where)) {
            $clause = '';
            foreach ($query->where as $where) {
                $clause .= $this->_buildWhere($query, $where);
            }
            if (!empty($clause)) {
                $clauses[] = '('.$clause.')';
            }
        }

        foreach ($query->link as $link) {
            $clauses = array_merge($clauses, $this->_where($link));
        }

        return $clauses;
    }
200678
public function determineSubType($query)
    {
        /**
         * First we get rid of all PREFIX information.
         */
        $adaptedQuery = preg_replace('/PREFIX\s+[a-z0-9]+\:\s*\<[a-z0-9\:\/\.\#\-]+\>/', '', $query);

        // remove trailing whitespaces
        $adaptedQuery = trim($adaptedQuery);

        // only lower chars
        $adaptedQuery = strtolower($adaptedQuery);

        $firstPart = substr($adaptedQuery, 0, 8);

        switch ($firstPart) {
            // CLEAR GRAPH
            case 'clear gr':
                return 'clearGraph';

            // CREATE GRAPH
            case 'create g':
                return 'createGraph';

            // CREATE SILENT GRAPH
            case 'create s':
                return 'createSilentGraph';

            // DROP GRAPH
            case 'drop gra':
                return 'dropGraph';

            // DROP SILENT GRAPH
            case 'drop sil':
                return 'dropSilentGraph';

            default:
                return null;
        }
    }
831101
public function query($query)
    {
        // Replace prefix placeholder with prefix
        $query = str_replace("{prefix}", $this->prefix, $query);

        // Log last query and query count
        $this->lastQuery = $query;
        $this->queryCount++;

        // Query database
        return $this->connection->query($query);
    }
1019338
public function castTypes(Query $query, array $data) {
        if ($columns = $query->getRepository()->getSchema()->getColumns()) {
            foreach ($columns as $column) {
                $field = $column['field'];

                if (array_key_exists($field, $data)) {
                    if ($data[$field] !== null) {
                        $data[$field] = AbstractType::factory($column['type'], $this->getDriver())->to($data[$field]);
                    }
                } else if (in_array($query->getType(), [Query::INSERT, Query::MULTI_INSERT], true) && array_key_exists('default', $column)) {
                    $data[$field] = $column['default'];
                }
            }
        }

        return $data;
    }
1200230
public function findRaw($query) {
        $this->_type = self::QUERY_RAW;
        $this->_query = $query;

        return $this;
    }
755313
protected function _callQuery($query)
    {
        $query->contain($this->type['contain']);
        $extQuery = $this->type['query'];
        return $extQuery($query);
    }
873648
public function query($query = NULL) {
        if (isset($query)) {
            $this->setQuery(self::cleanQuery($query));
            return $this;
        }
        return $this->getQuery();
    }
854486
public function withQuery($query)
    {
        if (!is_string($query) && !method_exists($query, '__toString')) {
            throw new InvalidArgumentException('Uri query must be a string');
        }
        $query = ltrim((string)$query, '?');
        $clone = clone $this;
        $clone->query = Validator::checkQuery($query);

        return $clone;
    }
808358
public function scopeFilteredByType(Builder $query, $type = null)
    {
        $type = is_null($type) ? request('f', 'all') : $type;

        if (in_array($type, ['audio', 'document', 'image', 'video', 'embedded']))
        {
            $query->whereType($type);
        }

        return $query;
    }
1113273
public function setQuery($query)
    {
        $this->query = null;
        if (is_string($query)) {
            $this->query = ltrim($query, '?');
        }
        return $this;
    }
705270
public function search($query)
    {
        $classes = $this->getClassMetadata();
        return $this->_sm->getUnitOfWork()->loadCollection($classes, $query);
    }
1042140
public function findTypes($query)
    {
        $facet = new TermsAggregation('type');
        $facet->setField('_type');
        $facet->setSize(200);
        $query->aggregate($facet);
        return $query->limit(1);
    }
460825
public function getQueryType($query)
    {
        $ipTools = new IpTools;

        if ($ipTools->validIp($query, 'ipv4', false)) {
            if ($ipTools->validIp($query, 'ipv4')) {
                return self::QTYPE_IPV4;
            } else {
                return self::QTYPE_UNKNOWN;
            }
        } elseif ($ipTools->validIp($query, 'ipv6', false)) {
            if ($ipTools->validIp($query, 'ipv6')) {
                return self::QTYPE_IPV6;
            } else {
                return self::QTYPE_UNKNOWN;
            }
        } elseif (!empty($query) && strpos($query, '.') !== false) {
            return self::QTYPE_DOMAIN;
        } elseif (!empty($query) && strpos($query, '.') === false) {
            return self::QTYPE_AS;
        } else {
            return self::QTYPE_UNKNOWN;
        }
    }
1351091
public function determineSubType($query)
    {
        $query = strtolower($query);

        if (false !== strpos($query, 'describe')) {
            // Check for e.g. DESCRIBE ?x WHERE { ... }
            if (false !== strpos($query, 'where')
                && false !== strpos($query, '{')
                && false !== strpos($query, '}')) {
                return 'describeWhere';

            // Assume its just e.g. DESCRIBE ?x
            } else {
                return 'describe';
            }
        } else {
            return null;
        }
    }
443198
function setQuery($query)
    {
        if ($query !== null) {
            $q = $this->getQuery();
            $q->with($q::parseWith($query));
        }

        return $this;
    }