very crude but working doc search

This commit is contained in:
redmatrix 2015-07-05 21:09:04 -07:00
parent f20933e1e0
commit 4abb114474
2 changed files with 55 additions and 1 deletions

View file

@ -137,6 +137,14 @@ use SSL, your webserver must not listen on port 443 at all.
cd mywebsite cd mywebsite
util/update_addon_repo matrix util/update_addon_repo matrix
- Create searchable represenations of the online documentation. You may do this any time
that the documentation is updated.
cd mywebsite
util/importdoc
3. Create an empty database and note the access details (hostname, username, 3. Create an empty database and note the access details (hostname, username,
password, database name). password, database name).

View file

@ -12,6 +12,9 @@
function load_doc_file($s) { function load_doc_file($s) {
$lang = get_app()->language; $lang = get_app()->language;
if(! isset($lang)) if(! isset($lang))
@ -49,6 +52,30 @@ function find_doc_file($s) {
return ''; return '';
} }
function search_doc_files($s) {
$a = get_app();
$itemspage = get_pconfig(local_channel(),'system','itemspage');
$a->set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start']));
// If the file was edited more recently than we've stored a copy in the database, use the file.
// The stored database item will be searchable, the file won't be.
$r = q("select item_id.sid, item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and
body regexp '%s' and item_type = %d order by created desc $pager_sql",
dbesc($s),
intval(ITEM_TYPE_DOC)
);
return $r;
}
function store_doc_file($s) { function store_doc_file($s) {
@ -93,7 +120,7 @@ function store_doc_file($s) {
} }
if($x['success']) { if($x['success']) {
update_remote_id($sys['channel_id'],$x['item_id'],ITEM_TYPE_DOC,$s,'docfile',0,$item['mid']); update_remote_id($sys,$x['item_id'],ITEM_TYPE_DOC,$s,'docfile',0,$item['mid']);
} }
@ -103,6 +130,25 @@ function store_doc_file($s) {
function help_content(&$a) { function help_content(&$a) {
nav_set_selected('help'); nav_set_selected('help');
if($_REQUEST['search']) {
$r = search_doc_files($_REQUEST['search']);
if($r) {
$o .= '<ul>';
foreach($r as $rr) {
$dirname = dirname($rr['sid']);
$fname = basename($rr['sid']);
$fname = substr($fname,0,strrpos($fname,'.'));
$path = trim(substr($dirname,4),'/');
$o .= '<li><a href="help/' . (($path) ? $path . '/' : '') . $fname . '" >' . ucwords(str_replace('_',' ',notags($fname))) . '</a></li>';
}
$o .= '</ul>';
}
return $o;
}
global $lang; global $lang;
$doctype = 'markdown'; $doctype = 'markdown';