<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.mysql-xdevapi-collection.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'mysql-xdevapi-collection.createindex.php',
    1 => 'Collection::createIndex',
    2 => 'Create collection index',
  ),
  'up' => 
  array (
    0 => 'class.mysql-xdevapi-collection.php',
    1 => 'mysql_xdevapi\\Collection',
  ),
  'prev' => 
  array (
    0 => 'mysql-xdevapi-collection.count.php',
    1 => 'Collection::count',
  ),
  'next' => 
  array (
    0 => 'mysql-xdevapi-collection.dropindex.php',
    1 => 'Collection::dropIndex',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mysql_xdevapi/mysql_xdevapi/collection/createindex.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mysql-xdevapi-collection.createindex" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Collection::createIndex</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">Collection::createIndex</span> &mdash; <span class="dc-title">Create collection index</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysql-xdevapi-collection.createindex-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>mysql_xdevapi\Collection::createIndex</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$index_name</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$index_desc_json</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="para rdfs-comment">
    Creates an index on the collection.
  </p>
  <p class="para">
    An exception is thrown if an index with the same name already exists,
    or if index definition is not correctly formed.
   </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mysql-xdevapi-collection.createindex-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">index_name</code></dt>
    <dd>
     <p class="para">
      The name of the index that to create. This name must be a valid index name as 
      accepted by the <code class="literal">CREATE INDEX</code> SQL query.
     </p>
    </dd>
   
   
    <dt><code class="parameter">index_desc_json</code></dt>
    <dd>
     <p class="para">
      Definition of the index to create. It contains an array of IndexField objects,
      and each object describes a single document member to include in the index, 
      and an optional string for the type of index that might be INDEX (default) or SPATIAL.
     </p>
     <p class="para">
      A single IndexField description consists of the following fields:
     </p>
     <ul class="itemizedlist">
      <li class="listitem">
        <p class="para">
          <code class="code">field</code>: string, the full document path to the document member or field to be indexed.
        </p>
      </li>
      <li class="listitem">
       <p class="para">
        <code class="code">type</code>: string, one of the supported SQL column types to map the field into.
        For numeric types, the optional UNSIGNED keyword may follow.
        For the TEXT type, the length to consider for indexing may be added.
       </p>
      </li>
      <li class="listitem">
        <p class="para">
          <code class="code">required</code>: bool, (optional) true if the field is required to exist in the document. 
          Defaults to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, except for <code class="literal">GEOJSON</code> where it defaults to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
         </p>
       </li>
      <li class="listitem">
        <p class="para">
          <code class="code">options</code>: integer, (optional) special option flags for use 
          when decoding <code class="literal">GEOJSON</code> data.
        </p>
      </li>
      <li class="listitem">
        <p class="para">
          <code class="code">srid</code>: integer, (optional) srid value for use when 
          decoding <code class="literal">GEOJSON</code> data.
        </p>
      </li>
      </ul>

      <p class="para">
        It is an error to include other fields not described above in 
        IndexDefinition or IndexField documents.
      </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysql-xdevapi-collection.createindex-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
 </div>


 <div class="refsect1 examples" id="refsect1-mysql-xdevapi-collection.createindex-examples">
  <h3 class="title">Esempi</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>mysql_xdevapi\Collection::createIndex()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$session </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_xdevapi\getSession</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysqlx://user:password@localhost"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sql</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP DATABASE IF EXISTS addressbook"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sql</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE DATABASE addressbook"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$schema     </span><span style="color: #007700">= </span><span style="color: #0000BB">$session</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getSchema</span><span style="color: #007700">(</span><span style="color: #DD0000">"addressbook"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$collection </span><span style="color: #007700">= </span><span style="color: #0000BB">$schema</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createCollection</span><span style="color: #007700">(</span><span style="color: #DD0000">"people"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Creating a text index<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createIndex</span><span style="color: #007700">(<br />  </span><span style="color: #DD0000">'myindex1'</span><span style="color: #007700">, <br />  </span><span style="color: #DD0000">'{"fields": [{<br />    "field": "$.name", <br />    "type": "TEXT(25)", <br />    "required": true}], <br />    "unique": false}'<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// A spatial index<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createIndex</span><span style="color: #007700">(<br />  </span><span style="color: #DD0000">'myindex2'</span><span style="color: #007700">, <br />  </span><span style="color: #DD0000">'{"fields": [{<br />    "field": "$.home", <br />    "type": "GEOJSON", <br />    "required": true}], <br />    "type": "SPATIAL"}'<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Index with multiple fields<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">createIndex</span><span style="color: #007700">(<br />  </span><span style="color: #DD0000">'myindex3'</span><span style="color: #007700">, <br />  </span><span style="color: #DD0000">'{"fields": [<br />    {<br />      "field": "$.name",<br />      "type": "TEXT(20)",<br />      "required": true<br />    },<br />    {<br />      "field": "$.age",<br />      "type": "INTEGER"<br />    },<br />    {<br />      "field": "$.job",<br />      "type": "TEXT(30)",<br />      "required": false<br />    }<br />  ],<br />  "unique": true<br />  }'<br /></span><span style="color: #007700">);</span></span></code></div>
   </div>

  </div>
 </div>


</div><?php manual_footer($setup); ?>