3 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__
).'/../').'/');
4 define('NOSESSION', 1);
5 require_once(DOKU_INC
.'inc/init.php');
8 * Update the Search Index from command line
10 class IndexerCLI
extends DokuCLI
{
12 private $quiet = false;
13 private $clear = false;
16 * Register options and arguments on the given $options object
18 * @param DokuCLI_Options $options
21 protected function setup(DokuCLI_Options
$options) {
23 'Updates the searchindex by indexing all new or changed pages. When the -c option is '.
24 'given the index is cleared first.'
27 $options->registerOption(
29 'clear the index before updating',
32 $options->registerOption(
34 'don\'t produce any output',
42 * Arguments and options have been parsed when this is run
44 * @param DokuCLI_Options $options
47 protected function main(DokuCLI_Options
$options) {
48 $this->clear
= $options->getOpt('clear');
49 $this->quiet
= $options->getOpt('quiet');
51 if($this->clear
) $this->clearindex();
62 $this->quietecho("Searching pages... ");
63 search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
64 $this->quietecho(count($data)." pages found.\n");
66 foreach($data as $val) {
67 $this->index($val['id']);
72 * Index the given page
77 $this->quietecho("$id... ");
78 idx_addPage($id, !$this->quiet
, $this->clear
);
79 $this->quietecho("done.\n");
83 * Clear all index files
85 function clearindex() {
86 $this->quietecho("Clearing index... ");
87 idx_get_indexer()->clear();
88 $this->quietecho("done.\n");
92 * Print message if not supressed
96 function quietecho($msg) {
97 if(!$this->quiet
) echo $msg;
102 $cli = new IndexerCLI();