Release preparation
[dokuwiki.git] / bin / indexer.php
blob13895c36a507e9b73930f1e2f023b186d3abd668
1 #!/usr/bin/php
2 <?php
3 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/');
4 define('NOSESSION', 1);
5 require_once(DOKU_INC.'inc/init.php');
7 /**
8 * Update the Search Index from command line
9 */
10 class IndexerCLI extends DokuCLI {
12 private $quiet = false;
13 private $clear = false;
15 /**
16 * Register options and arguments on the given $options object
18 * @param DokuCLI_Options $options
19 * @return void
21 protected function setup(DokuCLI_Options $options) {
22 $options->setHelp(
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(
28 'clear',
29 'clear the index before updating',
30 'c'
32 $options->registerOption(
33 'quiet',
34 'don\'t produce any output',
35 'q'
39 /**
40 * Your main program
42 * Arguments and options have been parsed when this is run
44 * @param DokuCLI_Options $options
45 * @return void
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();
53 $this->update();
56 /**
57 * Update the index
59 function update() {
60 global $conf;
61 $data = array();
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']);
71 /**
72 * Index the given page
74 * @param string $id
76 function index($id) {
77 $this->quietecho("$id... ");
78 idx_addPage($id, !$this->quiet, $this->clear);
79 $this->quietecho("done.\n");
82 /**
83 * Clear all index files
85 function clearindex() {
86 $this->quietecho("Clearing index... ");
87 idx_get_indexer()->clear();
88 $this->quietecho("done.\n");
91 /**
92 * Print message if not supressed
94 * @param string $msg
96 function quietecho($msg) {
97 if(!$this->quiet) echo $msg;
101 // Main
102 $cli = new IndexerCLI();
103 $cli->run();