1<?php 2 3use dokuwiki\Extension\Plugin; 4 5/** 6 * Helper component for searchindex plugin 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Andreas Gohr <andi@splitbrain.org> 10 */ 11class helper_plugin_searchindex extends Plugin 12{ 13 /** 14 * Get list of all pages 15 * 16 * @return string[] List of page IDs 17 */ 18 public function getPagelist(): array 19 { 20 global $conf; 21 $data = []; 22 search($data, $conf['datadir'], 'search_allpages', []); 23 24 return array_column($data, 'id'); 25 } 26 27 /** 28 * Clear all index files 29 * 30 * @return bool True on success 31 */ 32 public function clearIndex(): bool 33 { 34 $indexer = idx_get_indexer(); 35 return $indexer->clear() !== false; 36 } 37 38 /** 39 * Index the given page 40 * 41 * We're doing basically the same as the real indexer but ignore the 42 * last index time here 43 * 44 * @param string $page Page ID to index 45 * @param bool $force Force reindexing even if page hasn't changed 46 * @return bool True on success 47 */ 48 public function indexPage(string $page, bool $force = false): bool 49 { 50 if (!$page) { 51 return false; 52 } 53 54 return idx_addPage($page, false, $force) !== false; 55 } 56} 57