3 if ('cli' != php_sapi_name()) die();
5 ini_set('memory_limit','128M');
6 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__
).'/../').'/');
7 require_once(DOKU_INC
.'inc/init.php');
8 require_once(DOKU_INC
.'inc/common.php');
9 require_once(DOKU_INC
.'inc/pageutils.php');
10 require_once(DOKU_INC
.'inc/search.php');
11 require_once(DOKU_INC
.'inc/indexer.php');
12 require_once(DOKU_INC
.'inc/auth.php');
13 require_once(DOKU_INC
.'inc/cliopts.php');
14 session_write_close();
18 $long_opts = array('help', 'clear', 'update', 'quiet');
19 $OPTS = Doku_Cli_Opts
::getOptions(__FILE__
,$short_opts,$long_opts);
20 if ( $OPTS->isError() ) {
21 fwrite( STDERR
, $OPTS->getMessage() . "\n");
28 foreach ($OPTS->options
as $key => $val) {
45 #------------------------------------------------------------------------------
48 if($CLEAR) _clearindex();
53 #------------------------------------------------------------------------------
56 print "Usage: indexer.php <options>
58 Updates the searchindex by indexing all new or changed pages
59 when the -c option is given the index is cleared first.
62 -h, --help show this help and exit
63 -c, --clear clear the index before updating
64 -q, --quiet don't produce any output
72 $INDEXER = idx_get_indexer();
75 _quietecho("Searching pages... ");
76 search($data,$conf['datadir'],'search_allpages',array('skipacl' => true));
77 _quietecho(count($data)." pages found.\n");
79 foreach($data as $val){
89 _quietecho("$id... ");
90 idx_addPage($id, !$QUIET, $CLEAR);
91 _quietecho("done.\n");
95 * lock the indexer system
99 $lock = $conf['lockdir'].'/_indexer.lock';
101 while(!@mkdir
($lock, $conf['dmode'])){
102 if(time()-@filemtime
($lock) > 60*5){
103 // looks like a stale lock - remove it
109 _quietecho("Waiting for lockfile (max. 5 min)");
115 if($conf['dperm']) chmod($lock, $conf['dperm']);
116 if($said) _quietecho("\n");
120 * unlock the indexer sytem
124 $lock = $conf['lockdir'].'/_indexer.lock';
129 * Clear all index files
131 function _clearindex(){
134 _quietecho("Clearing index... ");
135 io_saveFile($conf['indexdir'].'/page.idx','');
136 io_saveFile($conf['indexdir'].'/title.idx','');
137 io_saveFile($conf['indexdir'].'/pageword.idx','');
138 io_saveFile($conf['indexdir'].'/metadata.idx','');
139 $dir = @opendir
($conf['indexdir']);
141 while(($f = readdir($dir)) !== false){
142 if(substr($f,-4)=='.idx' &&
143 (substr($f,0,1)=='i' ||
substr($f,0,1)=='w'
144 ||
substr($f,-6)=='_w.idx' ||
substr($f,-6)=='_i.idx' ||
substr($f,-6)=='_p.idx'))
145 @unlink
($conf['indexdir']."/$f");
148 @unlink
($conf['indexdir'].'/lengths.idx');
149 _quietecho("done.\n");
153 function _quietecho($msg) {
155 if(!$QUIET) echo $msg;
158 //Setup VIM: ex: et ts=2 :