UpgradeSimIndex.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\SentSim;
  5. use App\Models\SentSimIndex;
  6. use Illuminate\Support\Facades\DB;
  7. class UpgradeSimIndex extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:sim.index';
  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. if(\App\Tools\Tools::isStop()){
  38. return 0;
  39. }
  40. $result = DB::select('select count(*) from (select sent1 from sent_sims where sim>0.5 group by sent1) T');
  41. $bar = $this->output->createProgressBar($result[0]->count);
  42. foreach (SentSim::selectRaw('sent1,count(*)')
  43. ->where('sim','>',0.5)
  44. ->groupBy('sent1')->cursor() as $sent) {
  45. SentSimIndex::updateOrInsert(
  46. ['sent_id'=>$sent->sent1],
  47. ['count'=>$sent->count,]);
  48. $bar->advance();
  49. }
  50. $bar->finish();
  51. return 0;
  52. }
  53. }