Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo::addIndex PHP Method

addIndex() public method

Add a index for this Document.
public addIndex ( array $keys, array $options = [] )
$keys array Array of keys for the index.
$options array Array of options for the index.
    public function addIndex($keys, array $options = array())
    {
        $this->indexes[] = array('keys' => array_map(function ($value) {
            if ($value == 1 || $value == -1) {
                return (int) $value;
            }
            if (is_string($value)) {
                $lower = strtolower($value);
                if ($lower === 'asc') {
                    return 1;
                } elseif ($lower === 'desc') {
                    return -1;
                }
            }
            return $value;
        }, $keys), 'options' => $options);
    }

Usage Example

Beispiel #1
0
 private function addIndex(ClassMetadataInfo $class, $index, array $keys = array())
 {
     $keys = array_merge($keys, $index->keys);
     $options = array();
     $allowed = array('name', 'dropDups', 'background', 'safe', 'unique', 'sparse', 'expireAfterSeconds');
     foreach ($allowed as $name) {
         if (isset($index->{$name})) {
             $options[$name] = $index->{$name};
         }
     }
     $options = array_merge($options, $index->options);
     $class->addIndex($keys, $options);
 }
All Usage Examples Of Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo::addIndex
ClassMetadataInfo