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();
16 // Version tag used to force rebuild on upgrade
17 // Need to keep in sync with lib/exe/indexer.php
18 if(!defined('INDEXER_VERSION')) define('INDEXER_VERSION', 2);
22 $long_opts = array('help', 'clear', 'update', 'quiet');
23 $OPTS = Doku_Cli_Opts
::getOptions(__FILE__
,$short_opts,$long_opts);
24 if ( $OPTS->isError() ) {
25 fwrite( STDERR
, $OPTS->getMessage() . "\n");
31 foreach ($OPTS->options
as $key => $val) {
48 #------------------------------------------------------------------------------
51 if($CLEAR) _clearindex();
56 #------------------------------------------------------------------------------
59 print "Usage: indexer.php <options>
61 Updates the searchindex by indexing all new or changed pages
62 when the -c option is given the index is cleared first.
65 -h, --help show this help and exit
66 -c, --clear clear the index before updating
67 -q, --quiet don't produce any output
74 // upgrade to version 2
75 if (!@file_exists
($conf['indexdir'].'/pageword.idx')){
77 idx_upgradePageWords();
82 _quietecho("Searching pages... ");
83 search($data,$conf['datadir'],'search_allpages',array('skipacl' => true));
84 _quietecho(count($data)." pages found.\n");
86 foreach($data as $val){
94 // if not cleared only update changed and new files
96 $idxtag = metaFN($id,'.indexed');
97 if(@file_exists
($idxtag)){
98 if(io_readFile($idxtag) >= INDEXER_VERSION
){
99 $last = @filemtime
(metaFN($id,'.indexed'));
100 if($last > @filemtime
(wikiFN($id))) return;
106 _quietecho("$id... ");
108 io_saveFile(metaFN($id,'.indexed'),INDEXER_VERSION
);
109 _quietecho("done.\n");
114 * lock the indexer system
118 $lock = $conf['lockdir'].'/_indexer.lock';
120 while(!@mkdir
($lock, $conf['dmode'])){
121 if(time()-@filemtime
($lock) > 60*5){
122 // looks like a stale lock - remove it
128 _quietecho("Waiting for lockfile (max. 5 min)");
134 if($conf['dperm']) chmod($lock, $conf['dperm']);
135 if($said) _quietecho("\n");
139 * unlock the indexer sytem
143 $lock = $conf['lockdir'].'/_indexer.lock';
148 * Clear all index files
150 function _clearindex(){
153 _quietecho("Clearing index... ");
154 io_saveFile($conf['indexdir'].'/page.idx','');
155 $dir = @opendir
($conf['indexdir']);
157 while(($f = readdir($dir)) !== false){
158 if(substr($f,-4)=='.idx' &&
159 (substr($f,0,1)=='i' ||
substr($f,0,1)=='w'))
160 @unlink
($conf['indexdir']."/$f");
163 _quietecho("done.\n");
167 function _quietecho($msg) {
169 if(!$QUIET) echo $msg;
172 //Setup VIM: ex: et ts=2 enc=utf-8 :