UpgradeFts.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\BookTitle;
  5. use App\Models\FtsText;
  6. use App\Models\WbwTemplate;
  7. class UpgradeFts extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:fts {--content : upgrade col content}
  15. {para?}
  16. {--test : output log}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'upgrade full text search table';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return int
  36. */
  37. public function handle()
  38. {
  39. if($this->option('content')){
  40. if(!empty($this->argument('para'))){
  41. $para = explode('-',$this->argument('para'));
  42. }
  43. for ($iBook=1; $iBook <= 217; $iBook++) {
  44. if(isset($para[0]) && $para[0] != $iBook){
  45. continue;
  46. }
  47. # code...
  48. $this->info('book:'.$iBook);
  49. $maxParagraph = WbwTemplate::where('book',$iBook)->max('paragraph');
  50. $bar = $this->output->createProgressBar($maxParagraph-1);
  51. for($iPara=1; $iPara <= $maxParagraph; $iPara++){
  52. if(isset($para[1]) && $para[1] != $iPara){
  53. $bar->advance();
  54. continue;
  55. }
  56. $content = $this->getContent($iBook,$iPara);
  57. if($this->option('test')){
  58. $this->info($content);
  59. }else{
  60. //TODO update bold
  61. FtsText::where('book',$iBook)->where('paragraph',$iPara)->update(['content'=>$content]);
  62. }
  63. $bar->advance();
  64. }
  65. $bar->finish();
  66. $this->info('done');
  67. }
  68. }
  69. return 0;
  70. }
  71. private function getContent($book,$para){
  72. $words = WbwTemplate::where('book',$book)
  73. ->where('paragraph',$para)
  74. ->where('type',"<>",".ctl.")
  75. ->orderBy('wid')->get();
  76. $content = '';
  77. foreach ($words as $word) {
  78. if($word->style === 'bld'){
  79. if(strpos($word->word,"{")===FALSE){
  80. $content .= "**{$word->word}** ";
  81. }else{
  82. $content .= str_replace(['{','}'],['**','** '],$word->word);
  83. }
  84. }else if($word->style === 'note'){
  85. $content .= " _{$word->word}_ ";
  86. }else{
  87. $content .= $word->word . " ";
  88. }
  89. }
  90. return $content;
  91. }
  92. }