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