UpgradeDictDefaultMeaning.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\UserDict;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Support\Facades\Log;
  7. class UpgradeDictDefaultMeaning extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:dict.default.meaning';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '找出单词的首选意思。用于搜索列表';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. # 获取字典中所有的语言
  38. $langInDict = UserDict::select('language')->groupBy('language')->get();
  39. $languages = [];
  40. foreach ($langInDict as $lang) {
  41. if(!empty($lang["language"])){
  42. $languages[] = $lang["language"];
  43. }
  44. }
  45. print_r($languages);
  46. foreach ($languages as $thisLang) {
  47. Log::info("running $thisLang");
  48. $bar = $this->output->createProgressBar(UserDict::where('source','_PAPER_')
  49. ->where('language',$thisLang)->count());
  50. foreach (UserDict::where('source','_PAPER_')
  51. ->where('language',$thisLang)
  52. ->select('word','note')
  53. ->cursor() as $word) {
  54. Cache::put("dict_first_mean/{$thisLang}/{$word['word']}", mb_substr($word['note'],0,50,"UTF-8") ,24*3600);
  55. $bar->advance();
  56. }
  57. $bar->finish();
  58. }
  59. Log::info("running com");
  60. $bar = $this->output->createProgressBar(UserDict::where('source','_PAPER_')->count());
  61. foreach (UserDict::where('source','_PAPER_')
  62. ->select('word','note')
  63. ->cursor() as $word) {
  64. $key = "dict_first_mean/com/{$word['word']}";
  65. Cache::put($key, mb_substr($word['note'],0,50,"UTF-8") ,24*3600);
  66. $bar->advance();
  67. }
  68. $bar->finish();
  69. return 0;
  70. }
  71. }