public function invoke(ElasticSearch $elastic) { $res = $elastic->analyze($this->in->getArgument('analyzer'), $this->in->getArgument('query')); foreach ($res['tokens'] as $token) { $this->out->writeln("{$token['type']} {$token['token']}"); } }
public function invoke(ElasticSearch $elastic, Paths $paths) { $raw = file_get_contents($paths->getApp() . '/config/synonyms.esn'); $output = []; foreach (explode("\n", $raw) as $line) { $line = preg_replace('~\\s*#.*$~m', '', $line); // remove comments if (!$line) { continue; } $parts = preg_split('~\\s*(=>|,)\\s*~', $line, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); foreach ($parts as &$part) { if ($part === '=>' || $part === ',') { continue; } $words = []; foreach ($elastic->analyze('synonyms_compiler', $part)['tokens'] as $token) { $words[] = $token['token']; } $part = implode(' ', $words); } $output[] = '- "' . implode(' ', $parts) . '"'; } $content = "# Do not edit this file directly! Instead,\n"; $content .= "# edit synonyms.esn and run elasticsearch:build-synonyms command.\n\n"; $content .= str_replace(' ,', ',', implode("\n", $output)) . "\n"; file_put_contents($paths->getApp() . '/config/synonyms.compiled.neon', $content); $this->out->writeln('<info>Synonyms compiled</info>'); }