summaryrefslogtreecommitdiff
path: root/platform/www/bin/indexer.php
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2022-03-08 13:08:34 +0000
committerYaco <franco@reevo.org>2022-03-08 13:08:34 +0000
commitc985c40d3f3fc6a2be3be3186df3bf2f32189475 (patch)
treecee11f5e5a7e351ee0fec36d58d72cbee4f7e49b /platform/www/bin/indexer.php
first commit after acervus codebase
Diffstat (limited to 'platform/www/bin/indexer.php')
-rwxr-xr-xplatform/www/bin/indexer.php107
1 files changed, 107 insertions, 0 deletions
diff --git a/platform/www/bin/indexer.php b/platform/www/bin/indexer.php
new file mode 100755
index 0000000..c8c8361
--- /dev/null
+++ b/platform/www/bin/indexer.php
@@ -0,0 +1,107 @@
+#!/usr/bin/env php
+<?php
+
+use splitbrain\phpcli\CLI;
+use splitbrain\phpcli\Options;
+
+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 CLI {
+
+ private $quiet = false;
+ private $clear = false;
+
+ /**
+ * Register options and arguments on the given $options object
+ *
+ * @param Options $options
+ * @return void
+ */
+ protected function setup(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 Options $options
+ * @return void
+ */
+ protected function main(Options $options) {
+ $this->clear = $options->getOpt('clear');
+ $this->quiet = $options->getOpt('quiet');
+
+ if($this->clear) $this->clearindex();
+
+ $this->update();
+ }
+
+ /**
+ * Update the index
+ */
+ protected 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
+ */
+ protected function index($id) {
+ $this->quietecho("$id... ");
+ idx_addPage($id, !$this->quiet, $this->clear);
+ $this->quietecho("done.\n");
+ }
+
+ /**
+ * Clear all index files
+ */
+ protected function clearindex() {
+ $this->quietecho("Clearing index... ");
+ idx_get_indexer()->clear();
+ $this->quietecho("done.\n");
+ }
+
+ /**
+ * Print message if not supressed
+ *
+ * @param string $msg
+ */
+ protected function quietecho($msg) {
+ if(!$this->quiet) echo $msg;
+ }
+}
+
+// Main
+$cli = new IndexerCLI();
+$cli->run();