예제 #1
0
파일: schema.php 프로젝트: nyan-cat/easyweb
 function solr()
 {
     $document = new \xml\document();
     $fields = $document->element('fields');
     $this->traverse(function ($path, $property) use($document, $fields) {
         $types = ['boolean' => 'boolean', 'datetime' => 'date', 'enum' => 'string', 'integer' => 'int', 'number' => 'float', 'string' => 'string'];
         $required = (isset($property->required) and $property->required) ? 'true' : 'false';
         $stored = 'true';
         $multiValued = 'false';
         if (isset($types[$property->type])) {
             $field = $document->element('field');
             $field['@name'] = $path;
             $field['@type'] = $types[$property->type];
             $field['@required'] = $required;
             $field['@indexed'] = in_array($property->type, ['string']) ? (isset($property->indexed) and $property->indexed) ? 'true' : 'false' : 'true';
             $field['@stored'] = $stored;
             $field['@multiValued'] = $multiValued;
             $fields->append($field);
         }
     });
     $document->append($fields);
     return $document->render();
 }