I've made some progress and got a draft of a working solution
I've adapted the docsearch plugin's action/search.php to do the dirty work
Next thing would be to clean up code, add comments and rearrange walk function to return result count
so as to echo "no results found" if necessary
<?php
/**
* Script to search in uploaded pdf documents
*
* @author Dominik Eckelmann <eckelmann@cosmocode.de>
* @author @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
*/
if(!defined('DOKU_INC')) die();
class action_plugin_docsearch_search extends DokuWiki_Action_Plugin {
private $backupConfig;
function register(Doku_Event_Handler $controller) {
$controller->register_hook('TPL_CONTENT_DISPLAY', 'AFTER', $this, 'display', array());
}
function display(Doku_Event &$event, $param) {
global $ACT;
global $conf;
global $QUERY;
global $lang;
// only work with search
if($ACT !== 'search') return;
echo "<h2>Documents</h2>";
function walk($dir,$query) {
if(!is_readable($dir)) return;
if(!is_dir($dir)) return;
$handle = opendir($dir);
if(!$handle) return;
while(false !== ($file = readdir($handle))) {
if($file == '.' || $file == '..') continue;
$path = "$dir\\$file";
if(is_file($path)) {
if (strpos($path,$query) !== false) {
$url = str_replace('C:\Data\home\data\media\ims\\',"",$path);
echo "<a href='/_media/ims/$url'>$file</a><br>";
$docfound++;
}
continue;
}
if(is_dir($path)) {
walk($path,$query);
continue;
}
}
}
$base = "C:\Data\home\data\media\ims";
walk($base,$QUERY);
/*
// backup the config array
$this->backupConfig = $conf;
// change index/pages folder for DocSearch
$conf['indexdir'] = $conf['savedir'] . '/docsearch/index';
$conf['datadir'] = $conf['savedir'] . '/docsearch/pages';
$data = ft_pageSearch($QUERY, $regex);
if(empty($data)) {
$conf = $this->backupConfig;
return;
}
$searchResults = array();
$runs = 0;
foreach($data as $id => $hits) {
$searchResults[$id] = array();
$searchResults[$id]['hits'] = $hits;
if($runs++ < $this->getConf('showSnippets')) {
$searchResults[$id]['snippet'] = ft_snippet($id, $regex);
}
}
$conf = $this->backupConfig;
echo '<h2>' . hsc($this->getLang('title')) . '</h2>';
echo '<div class="search_result">';
echo "ketek";
$num = 0;
foreach($searchResults as $id => $data) {
if($this->getConf('showUsage') !== 0) {
$usages = ft_mediause($id, $this->getConf('showUsage'));
} else {
$usages = array();
}
echo '<a href="' . ml($id) . '" title="" class="wikilink1">' . hsc($id) . '</a>: ';
echo '<span class="search_cnt">' . hsc($data['hits']) . ' ' . hsc($lang['hits']) . '</span>';
if(!empty($usages)) {
echo '<span class="usage">';
echo ', ' . hsc($this->getLang('usage')) . ' ';
foreach($usages as $usage) {
echo html_wikilink($usage);
}
echo '</span>';
}
if(isset($data['snippet'])) {
echo '<div class="search_snippet">';
echo $data['snippet'];
echo '</div>';
}
echo '<br />';
$num++;
}
echo '</div>';*/
}
}