4 use splitbrain\phpcli\CLI
;
5 use splitbrain\phpcli\Options
;
7 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__
) . '/../') . '/');
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) {
27 'Updates the searchindex by indexing all new or changed pages. When the -c option is ' .
28 'given the index is cleared first.'
31 $options->registerOption(
33 'clear the index before updating',
36 $options->registerOption(
38 'don\'t produce any output',
46 * Arguments and options have been parsed when this is run
48 * @param Options $options
51 protected function main(Options
$options) {
52 $this->clear
= $options->getOpt('clear');
53 $this->quiet
= $options->getOpt('quiet');
55 if($this->clear
) $this->clearindex();
66 $this->quietecho("Searching pages... ");
67 search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
68 $this->quietecho(count($data) . " pages found.\n");
70 foreach($data as $val) {
71 $this->index($val['id']);
76 * Index the given page
81 $this->quietecho("$id... ");
82 idx_addPage($id, !$this->quiet
, $this->clear
);
83 $this->quietecho("done.\n");
87 * Clear all index files
89 function clearindex() {
90 $this->quietecho("Clearing index... ");
91 idx_get_indexer()->clear();
92 $this->quietecho("done.\n");
96 * Print message if not supressed
100 function quietecho($msg) {
101 if(!$this->quiet
) echo $msg;
106 $cli = new IndexerCLI();