Command/CreateFullTextIndexesCommand.php
changeset 23 b435f8055cb4
parent 19 7051e55a3131
equal deleted inserted replaced
22:99c15cfe420b 23:b435f8055cb4
    41         if(is_null($file) || strlen($file) == 0)
    41         if(is_null($file) || strlen($file) == 0)
    42         {
    42         {
    43             $simulate = true;
    43             $simulate = true;
    44         }
    44         }
    45         
    45         
    46         $sql_code = "";
    46 
    47         $fields = $this->getContainer()->getParameter('wiki_tag.fields');
    47         $schema_utils = $this->getContainer()->get("wikitag.shema_utils");
    48         $def_columns = array();
       
    49         foreach ( $fields as $name => $field_def)
       
    50         {
       
    51             if(isset($field_def['type']))
       
    52             {
       
    53                 $type = $field_def['type'];
       
    54             }
       
    55             if(!isset($type) || is_null($type) || strlen($type) == 0)
       
    56             {
       
    57                 $type = "text";
       
    58             }
       
    59             
       
    60             if($type === 'text')
       
    61             {
       
    62                 $def_column = "$name(4096)";
       
    63             }
       
    64             else
       
    65             {
       
    66                 $def_column = $name;
       
    67             }
       
    68             $def_columns[] = $def_column;
       
    69             
       
    70             $sql_code .= "ALTER IGNORE TABLE wikitag_document DROP INDEX ${name}_document_fulltext_idx;\n";
       
    71             $sql_code .= "ALTER TABLE wikitag_document ADD FULLTEXT INDEX ${name}_document_fulltext_idx ($def_column);\n";
       
    72         }
       
    73         
    48         
    74         $sql_code .= "ALTER IGNORE TABLE wikitag_document DROP INDEX all_document_fulltext_idx;\n";
    49         $sql_code = implode(";".PHP_EOL, $schema_utils->createFullTextIndexes());
    75         $sql_code .= "ALTER TABLE wikitag_document ADD FULLTEXT INDEX all_document_fulltext_idx (".join(",", $def_columns).");\n";
       
    76         
       
    77         
    50         
    78         if($simulate)
    51         if($simulate)
    79         {
    52         {
    80             $output->writeln($sql_code);
    53             $output->writeln($sql_code);
    81         }
    54         }