public function index($collectionId, $type, array $attributes = [], $unique = false, array $indexOptions = [])
    {

        $urlParams  = [self::OPTION_COLLECTION => $collectionId];
        $bodyParams = [
            self::OPTION_TYPE   => $type,
            self::OPTION_FIELDS => $attributes,
        ];

        if ($unique !== null) {
            $bodyParams[self::OPTION_UNIQUE] = (bool) $unique;
        }

        $bodyParams = array_merge($bodyParams, $indexOptions);

        $url      = UrlHelper::appendParamsUrl(Urls::URL_INDEX, $urlParams);
        $response = $this->getConnection()->post($url, $this->json_encode_wrapper($bodyParams));

        $httpCode = $response->getHttpCode();
        switch ($httpCode) {
            case 404:
                throw new ClientException('Collection-identifier is unknown');

                break;
            case 400:
                throw new ClientException('cannot create unique index due to documents violating uniqueness');
                break;
        }

        return $response->getJson();
    }
public function index($collectionId, $type, array $attributes = [], $unique = false, array $indexOptions = [])
    {

        $urlParams  = [self::OPTION_COLLECTION => $collectionId];
        $bodyParams = [
            self::OPTION_TYPE   => $type,
            self::OPTION_FIELDS => $attributes,
        ];

        if ($unique !== null) {
            $bodyParams[self::OPTION_UNIQUE] = (bool) $unique;
        }

        $bodyParams = array_merge($bodyParams, $indexOptions);

        $url      = UrlHelper::appendParamsUrl(Urls::URL_INDEX, $urlParams);
        $response = $this->getConnection()->post($url, $this->json_encode_wrapper($bodyParams));

        $httpCode = $response->getHttpCode();
        switch ($httpCode) {
            case 404:
                throw new ClientException('Collection-identifier is unknown');

                break;
            case 400:
                throw new ClientException('cannot create unique index due to documents violating uniqueness');
                break;
        }

        return $response->getJson();
    }
public function index ( $ collectionId , $ type , array $ attributes = [ ] , $ unique = false , array $ indexOptions = [ ] ) { $ urlParams = [ self :: OPTION_COLLECTION => $ collectionId ] ; $ bodyParams = [ self :: OPTION_TYPE => $ type , self :: OPTION_FIELDS => $ attributes , ] ; if ( $ unique !== null ) { $ bodyParams [ self :: OPTION_UNIQUE ] = ( bool ) $ unique ; } $ bodyParams = array_merge ( $ bodyParams , $ indexOptions ) ; $ url = UrlHelper :: appendParamsUrl ( Urls :: URL_INDEX , $ urlParams ) ; $ response = $ this -> getConnection ( ) -> post ( $ url , $ this -> json_encode_wrapper ( $ bodyParams ) ) ; $ httpCode = $ response -> getHttpCode ( ) ; switch ( $ httpCode ) { case 404 : throw new ClientException ( 'Collection-identifier is unknown' ) ; break ; case 400 : throw new ClientException ( 'cannot create unique index due to documents violating uniqueness' ) ; break ; } return $ response -> getJson ( ) ; }
Creates an index on a collection on the server

This will create an index on the collection on the server and return its id

This will throw if the index cannot be created

@throws Exception

@param mixed  $collectionId - The id of the collection where the index is to be created
@param string $type         - index type: hash, skiplist, geo, fulltext, or persistent
@param array  $attributes   - an array of attributes that can be defined like array('a') or array('a', 'b.c')
@param bool   $unique       - true/false to create a unique index
@param array  $indexOptions - an associative array of options for the index like array('geoJson' => true, 'sparse' => false)

@return array - server response of the created index
Creates an index on a collection on the server