1#!/usr/bin/php 2<?php 3if ('cli' != php_sapi_name()) die(); 4 5ini_set('memory_limit','128M'); 6if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); 7require_once(DOKU_INC.'inc/init.php'); 8require_once(DOKU_INC.'inc/common.php'); 9require_once(DOKU_INC.'inc/pageutils.php'); 10require_once(DOKU_INC.'inc/search.php'); 11require_once(DOKU_INC.'inc/indexer.php'); 12require_once(DOKU_INC.'inc/auth.php'); 13require_once(DOKU_INC.'inc/cliopts.php'); 14session_write_close(); 15 16// handle options 17$short_opts = 'hcuq'; 18$long_opts = array('help', 'clear', 'update', 'quiet'); 19$OPTS = Doku_Cli_Opts::getOptions(__FILE__,$short_opts,$long_opts); 20if ( $OPTS->isError() ) { 21 fwrite( STDERR, $OPTS->getMessage() . "\n"); 22 _usage(); 23 exit(1); 24} 25$CLEAR = false; 26$QUIET = false; 27$INDEXER = null; 28foreach ($OPTS->options as $key => $val) { 29 switch ($key) { 30 case 'h': 31 case 'help': 32 _usage(); 33 exit; 34 case 'c': 35 case 'clear': 36 $CLEAR = true; 37 break; 38 case 'q': 39 case 'quiet': 40 $QUIET = true; 41 break; 42 } 43} 44 45#------------------------------------------------------------------------------ 46# Action 47 48if($CLEAR) _clearindex(); 49_update(); 50 51 52 53#------------------------------------------------------------------------------ 54 55function _usage() { 56 print "Usage: indexer.php <options> 57 58 Updates the searchindex by indexing all new or changed pages 59 when the -c option is given the index is cleared first. 60 61 OPTIONS 62 -h, --help show this help and exit 63 -c, --clear clear the index before updating 64 -q, --quiet don't produce any output 65"; 66} 67 68function _update(){ 69 global $conf; 70 global $INDEXER; 71 72 $INDEXER = idx_get_indexer(); 73 74 $data = array(); 75 _quietecho("Searching pages... "); 76 search($data,$conf['datadir'],'search_allpages',array('skipacl' => true)); 77 _quietecho(count($data)." pages found.\n"); 78 79 foreach($data as $val){ 80 _index($val['id']); 81 } 82} 83 84function _index($id){ 85 global $INDEXER; 86 global $CLEAR; 87 global $QUIET; 88 89 _quietecho("$id... "); 90 idx_addPage($id, !$QUIET, $CLEAR); 91 _quietecho("done.\n"); 92} 93 94/** 95 * Clear all index files 96 */ 97function _clearindex(){ 98 _quietecho("Clearing index... "); 99 idx_get_indexer()->clear(); 100 _quietecho("done.\n"); 101} 102 103function _quietecho($msg) { 104 global $QUIET; 105 if(!$QUIET) echo $msg; 106} 107 108//Setup VIM: ex: et ts=2 : 109