4 use splitbrain\phpcli\CLI
;
5 use splitbrain\phpcli\Options
;
7 if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__
. '/../') . '/');
8 define('NOSESSION', 1);
9 require_once(DOKU_INC
. 'inc/init.php');
12 * Update the Search Index from command line
14 class IndexerCLI
extends CLI
16 private $quiet = false;
17 private $clear = false;
20 * Register options and arguments on the given $options object
22 * @param Options $options
25 protected function setup(Options
$options)
28 'Updates the searchindex by indexing all new or changed pages. When the -c option is ' .
29 'given the index is cleared first.'
32 $options->registerOption(
34 'clear the index before updating',
37 $options->registerOption(
39 'don\'t produce any output',
47 * Arguments and options have been parsed when this is run
49 * @param Options $options
52 protected function main(Options
$options)
54 $this->clear
= $options->getOpt('clear');
55 $this->quiet
= $options->getOpt('quiet');
57 if ($this->clear
) $this->clearindex();
65 protected function update()
69 $this->quietecho("Searching pages... ");
70 search($data, $conf['datadir'], 'search_allpages', ['skipacl' => true]);
71 $this->quietecho(count($data) . " pages found.\n");
73 foreach ($data as $val) {
74 $this->index($val['id']);
79 * Index the given page
83 protected function index($id)
85 $this->quietecho("$id... ");
86 idx_addPage($id, !$this->quiet
, $this->clear
);
87 $this->quietecho("done.\n");
91 * Clear all index files
93 protected function clearindex()
95 $this->quietecho("Clearing index... ");
96 idx_get_indexer()->clear();
97 $this->quietecho("done.\n");
101 * Print message if not supressed
105 protected function quietecho($msg)
107 if (!$this->quiet
) echo $msg;
112 $cli = new IndexerCLI();