visuddhinanda 2 лет назад
Родитель
Сommit
bfd649644d
1 измененных файлов с 55 добавлено и 0 удалено
  1. 55 0
      app/Console/Commands/UpgradeSimIndex.php

+ 55 - 0
app/Console/Commands/UpgradeSimIndex.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\SentSim;
+use App\Models\SentSimIndex;
+use Illuminate\Support\Facades\DB;
+
+class UpgradeSimIndex extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'upgrade:sim.index';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '刷新相似句索引';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        SentSimIndex::where('id','>',0)->delete();
+        $result = DB::select('select count(*) from (select sent1 from sent_sims where sim>0.7  group by sent1) T');
+        $bar = $this->output->createProgressBar($result[0]->count);
+        foreach (SentSim::selectRaw('sent1,count(*)')->where('sim','>',0.7)->groupBy('sent1')->cursor() as $sent) {
+            SentSimIndex::insert(
+                ['sent_id'=>$sent->sent1,
+                'count'=>$sent->count,]);
+            $bar->advance();
+        }
+        $bar->finish();
+        return 0;
+    }
+}