New query debug command

This commit is contained in:
Mathieu Darse
2014-11-10 18:08:39 +01:00
parent 532f240ffd
commit 7d9b633043
3 changed files with 68 additions and 0 deletions

2
bin/console Normal file → Executable file
View File

@@ -14,6 +14,7 @@ namespace KonsoleKommander;
use Alchemy\Phrasea\Command\Plugin\ListPlugin; use Alchemy\Phrasea\Command\Plugin\ListPlugin;
use Alchemy\Phrasea\Command\Setup\H264ConfigurationDumper; use Alchemy\Phrasea\Command\Setup\H264ConfigurationDumper;
use Alchemy\Phrasea\Command\Setup\H264MappingGenerator; use Alchemy\Phrasea\Command\Setup\H264MappingGenerator;
use Alchemy\Phrasea\Command\SearchEngine\Debug\QueryParseCommand;
use Alchemy\Phrasea\Command\SearchEngine\IndexCreateCommand; use Alchemy\Phrasea\Command\SearchEngine\IndexCreateCommand;
use Alchemy\Phrasea\Command\SearchEngine\IndexDropCommand; use Alchemy\Phrasea\Command\SearchEngine\IndexDropCommand;
use Alchemy\Phrasea\Command\SearchEngine\IndexFull; use Alchemy\Phrasea\Command\SearchEngine\IndexFull;
@@ -127,6 +128,7 @@ if ($cli['search_engine.type'] === SearchEngineInterface::TYPE_ELASTICSEARCH) {
$cli->command(new IndexCreateCommand()); $cli->command(new IndexCreateCommand());
$cli->command(new IndexDropCommand()); $cli->command(new IndexDropCommand());
$cli->command(new IndexPopulateCommand()); $cli->command(new IndexPopulateCommand());
$cli->command(new QueryParseCommand());
} }
$cli->command(new WebsocketServer('ws-server:run')); $cli->command(new WebsocketServer('ws-server:run'));

View File

@@ -0,0 +1,61 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\SearchEngine\Debug;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\SearchEngine\Elastic\Indexer;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class QueryParseCommand extends Command
{
protected function configure()
{
$this
->setName('searchengine:query:parse')
->setDescription('Debug a search query')
->addArgument(
'query',
InputArgument::REQUIRED,
'The query to debug'
)
->addOption(
'raw',
false,
InputOption::VALUE_NONE,
'Only output query dump'
)
;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$string = $input->getArgument('query');
$raw = $input->getOption('raw');
if (!$raw) {
$output->writeln(sprintf('Parsing search query: <comment>%s</comment>', $string));
$output->writeln(str_repeat('-', 20));
}
$query = $this->container['query_parser']->parse($string);
$dump = $query->dump();
if (!$raw) {
$output->writeln($dump);
} else {
$output->write($dump);
}
}
}

View File

@@ -24,4 +24,9 @@ class SearchQuery
{ {
return (string) $this->root; return (string) $this->root;
} }
public function dump()
{
return (string) $this;
}
} }