TNTSearchQueryCommand.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Grav\Plugin\Console;
  3. use Grav\Console\ConsoleCommand;
  4. use Grav\Plugin\TNTSearchPlugin;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputOption;
  7. /**
  8. * Class IndexerCommand
  9. *
  10. * @package Grav\Plugin\Console
  11. */
  12. class TNTSearchQueryCommand extends ConsoleCommand
  13. {
  14. /** @var array */
  15. protected $options = [];
  16. /** @var array */
  17. protected $colors = [
  18. 'DEBUG' => 'green',
  19. 'INFO' => 'cyan',
  20. 'NOTICE' => 'yellow',
  21. 'WARNING' => 'yellow',
  22. 'ERROR' => 'red',
  23. 'CRITICAL' => 'red',
  24. 'ALERT' => 'red',
  25. 'EMERGENCY' => 'magenta'
  26. ];
  27. /**
  28. * @return void
  29. */
  30. protected function configure()
  31. {
  32. $this
  33. ->setName('query')
  34. ->setDescription('TNTSearch Query')
  35. ->addArgument(
  36. 'query',
  37. InputArgument::REQUIRED,
  38. 'The search query you wish to use to test the database'
  39. )
  40. ->addOption(
  41. 'language',
  42. 'l',
  43. InputOption::VALUE_OPTIONAL,
  44. 'optional language to search against (multi-language sites only)'
  45. )
  46. ->setHelp('The <info>query command</info> allows you to test the search engine')
  47. ;
  48. }
  49. /**
  50. * @return int
  51. */
  52. protected function serve(): int
  53. {
  54. /** @var string|null $langCode */
  55. $langCode = $this->input->getOption('language');
  56. /** @var string $query */
  57. $query = $this->input->getArgument('query');
  58. $this->setLanguage($langCode);
  59. $this->initializePages();
  60. $gtnt = TNTSearchPlugin::getSearchObjectType(['json' => true]);
  61. print_r($gtnt->search($query));
  62. $this->output->newLine();
  63. return 0;
  64. }
  65. }