diff --git a/bin/console b/bin/console old mode 100644 new mode 100755 index 7845c5e2de..3c087c5d48 --- a/bin/console +++ b/bin/console @@ -14,6 +14,7 @@ namespace KonsoleKommander; use Alchemy\Phrasea\Command\Plugin\ListPlugin; use Alchemy\Phrasea\Command\Setup\H264ConfigurationDumper; use Alchemy\Phrasea\Command\Setup\H264MappingGenerator; +use Alchemy\Phrasea\Command\SearchEngine\Debug\QueryParseCommand; use Alchemy\Phrasea\Command\SearchEngine\IndexCreateCommand; use Alchemy\Phrasea\Command\SearchEngine\IndexDropCommand; 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 IndexDropCommand()); $cli->command(new IndexPopulateCommand()); + $cli->command(new QueryParseCommand()); } $cli->command(new WebsocketServer('ws-server:run')); diff --git a/lib/Alchemy/Phrasea/Command/SearchEngine/Debug/QueryParseCommand.php b/lib/Alchemy/Phrasea/Command/SearchEngine/Debug/QueryParseCommand.php new file mode 100644 index 0000000000..a7e7249deb --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/SearchEngine/Debug/QueryParseCommand.php @@ -0,0 +1,61 @@ +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: %s', $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); + } + } +} diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/SearchQuery.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/SearchQuery.php index 25731c7649..2748f1e97c 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/SearchQuery.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/SearchQuery.php @@ -24,4 +24,9 @@ class SearchQuery { return (string) $this->root; } + + public function dump() + { + return (string) $this; + } }