1010 *
1111 * @package Grav\Plugin\Console
1212 */
13- class IndexerCommand extends ConsoleCommand
13+ class TNTSearchIndexerCommand extends ConsoleCommand
1414{
1515 /**
1616 * @var array
@@ -37,7 +37,18 @@ protected function configure()
3737 {
3838 $ this
3939 ->setName ('index ' )
40- ->addOption ('alt ' , null , InputOption::VALUE_NONE , 'alternative output ' )
40+ ->addOption (
41+ 'alt ' ,
42+ null ,
43+ InputOption::VALUE_NONE ,
44+ 'alternative output '
45+ )
46+ ->addOption (
47+ 'language ' ,
48+ 'l ' ,
49+ InputOption::VALUE_OPTIONAL ,
50+ 'optional language to index (multi-language sites only) '
51+ )
4152 ->setDescription ('TNTSearch Indexer ' )
4253 ->setHelp ('The <info>index command</info> re-indexes the search engine ' );
4354 }
@@ -47,32 +58,41 @@ protected function configure()
4758 */
4859 protected function serve ()
4960 {
61+ $ langCode = $ this ->input ->getOption ('language ' );
62+
63+ error_reporting (1 );
64+ $ this ->setLanguage ($ langCode );
5065 $ this ->initializePages ();
5166
5267 $ alt_output = $ this ->input ->getOption ('alt ' ) ? true : false ;
5368
5469 if ($ alt_output ) {
55- $ this ->doIndex ($ alt_output );
70+ $ output = $ this ->doIndex ($ langCode );
71+ $ this ->output ->write ($ output );
72+ $ this ->output ->writeln ('' );
5673 } else {
5774 $ this ->output ->writeln ('' );
5875 $ this ->output ->writeln ('<magenta>Re-indexing</magenta> ' );
5976 $ this ->output ->writeln ('' );
6077 $ start = microtime (true );
61- $ this ->doIndex ($ alt_output );
78+ $ output = $ this ->doIndex ($ langCode );
79+ $ this ->output ->write ($ output );
80+ $ this ->output ->writeln ('' );
6281 $ end = number_format (microtime (true ) - $ start ,1 );
6382 $ this ->output ->writeln ('' );
6483 $ this ->output ->writeln ('Indexed in ' . $ end . 's ' );
6584 }
6685 }
6786
68- private function doIndex ($ alt_output = false )
87+ /**
88+ * @param string|null $langCode
89+ * @return string
90+ */
91+ private function doIndex (string $ langCode = null ): string
6992 {
70- error_reporting (1 );
71-
72- [$ status , $ msg , $ output ] = TNTSearchPlugin::indexJob ();
93+ [,,$ output ] = TNTSearchPlugin::indexJob ($ langCode );
7394
74- $ this ->output ->write ($ output );
75- $ this ->output ->writeln ('' );
95+ return $ output ;
7696 }
7797}
7898
0 commit comments