Context support in concept finding command

This commit is contained in:
Mathieu Darse
2015-01-16 12:22:42 +01:00
parent dc2c9f8c7f
commit 1a23a23e18

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Command\Thesaurus;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\SearchEngine\Elastic\Indexer;
use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus\Term;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -30,6 +31,11 @@ class FindConceptsCommand extends Command
InputArgument::REQUIRED,
'Reverse search a term to infer concepts'
)
->addArgument(
'context',
InputArgument::OPTIONAL,
'Restrict search to a specific term context'
)
->addOption(
'locale',
null,
@@ -48,16 +54,22 @@ class FindConceptsCommand extends Command
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$term = $input->getArgument('term');
$context = $input->getArgument('context');
$raw = $input->getOption('raw');
if (!$raw) {
$output->writeln(sprintf('Finding linked concepts: <comment>%s</comment>', $term));
$message = sprintf('Finding linked concepts: <comment>%s</comment>', $term);
if ($context) {
$message .= sprintf(' (with context <comment>%s</comment>)', $context);
}
$output->writeln($message);
$output->writeln(str_repeat('-', 20));
}
$thesaurus = $this->container['thesaurus'];
$term = new Term($term, $context);
$locale = $input->getOption('locale');
$concepts = $thesaurus->findConcepts($term, null, $locale);
$concepts = $thesaurus->findConcepts($term, $locale);
if (count($concepts)) {
$output->writeln($concepts);