forked from dokuwiki/dokuwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexer.php
executable file
·103 lines (90 loc) · 2.37 KB
/
indexer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/php
<?php
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/');
define('NOSESSION', 1);
require_once(DOKU_INC.'inc/init.php');
/**
* Update the Search Index from command line
*/
class IndexerCLI extends DokuCLI {
private $quiet = false;
private $clear = false;
/**
* Register options and arguments on the given $options object
*
* @param DokuCLI_Options $options
* @return void
*/
protected function setup(DokuCLI_Options $options) {
$options->setHelp(
'Updates the searchindex by indexing all new or changed pages. When the -c option is '.
'given the index is cleared first.'
);
$options->registerOption(
'clear',
'clear the index before updating',
'c'
);
$options->registerOption(
'quiet',
'don\'t produce any output',
'q'
);
}
/**
* Your main program
*
* Arguments and options have been parsed when this is run
*
* @param DokuCLI_Options $options
* @return void
*/
protected function main(DokuCLI_Options $options) {
$this->clear = $options->getOpt('clear');
$this->quiet = $options->getOpt('quiet');
if($this->clear) $this->clearindex();
$this->update();
}
/**
* Update the index
*/
function update() {
global $conf;
$data = array();
$this->quietecho("Searching pages... ");
search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
$this->quietecho(count($data)." pages found.\n");
foreach($data as $val) {
$this->index($val['id']);
}
}
/**
* Index the given page
*
* @param string $id
*/
function index($id) {
$this->quietecho("$id... ");
idx_addPage($id, !$this->quiet, $this->clear);
$this->quietecho("done.\n");
}
/**
* Clear all index files
*/
function clearindex() {
$this->quietecho("Clearing index... ");
idx_get_indexer()->clear();
$this->quietecho("done.\n");
}
/**
* Print message if not supressed
*
* @param string $msg
*/
function quietecho($msg) {
if(!$this->quiet) echo $msg;
}
}
// Main
$cli = new IndexerCLI();
$cli->run();