2
0
Эх сурвалжийг харах

导出文件拆成小文件

visuddhinanda 2 жил өмнө
parent
commit
b9225c9b31

+ 12 - 2
app/Console/Commands/ExportFtsPali.php

@@ -52,8 +52,11 @@ class ExportFtsPali extends Command
                 return 1;
             }
         }
-        $fp = fopen($path.'/pali.syn','w') or die("Unable to open file!");
-        $count=0;
+
+        $pageSize = 10000;
+        $currPage = 1;
+        $fp = fopen($path."/pali-{$currPage}.syn",'w') or die("Unable to open file!");
+        $count = 0;
         foreach ($dictId as $key => $value) {
             $words = UserDict::where('dict_id',$value)
                              ->select('word')
@@ -64,6 +67,13 @@ class ExportFtsPali extends Command
                 if($count % 1000 === 0){
                     $this->info($count);
                 }
+                if($count % 10000 === 0){
+                    fclose($fp);
+                    $currPage++;
+                    $filename = "/pali-{$currPage}.syn";
+                    $this->info('new file filename='.$filename);
+                    $fp = fopen($path.$filename,'w') or die("Unable to open file!");
+                }
                 $parent = UserDict::where('dict_id',$value)
                              ->where('word',$word->word)
                              ->selectRaw('parent,char_length("parent")')