$value) { $words = UserDict::where('dict_id', $value) ->select('word') ->groupBy('word')->cursor(); $this->info('word count=' . count($words)); foreach ($words as $key => $word) { $count++; if ($count % 1000 === 0) { $this->info($count); } if ($count % 10000 === 0) { fclose($fp); $redisKey = 'export/fts/pali' . $filename; $content = file_get_contents($path . $filename); Redis::set($redisKey, $content); Redis::expire($redisKey, 3600 * 24 * 10); $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")') ->groupBy('parent')->orderBy('char_length', 'asc')->first(); if ($parent && !empty($parent->parent)) { $end = mb_substr($parent->parent, -1, null, "UTF-8"); if (in_array($end, ["ā", "ī", "ū"])) { $head = mb_substr($parent->parent, 0, mb_strlen($parent->parent) - 1, "UTF-8"); $newEnd = str_replace(["ā", "ī", "ū"], ["a", "i", "u"], $end); $parentWord = $head . $newEnd; } else { $parentWord = $parent->parent; } fwrite($fp, $word->word . ' ' . $parentWord . PHP_EOL); } else { $this->error('word no parent word=' . $word->word); } } } fclose($fp); return 0; } }