From f71f4f5359fe234960829868bf22081bf1f2d947 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 28 Feb 2010 12:32:01 +0100 Subject: added dokuwiki.search XMLRPC call FS#1882 --- lib/exe/xmlrpc.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'lib/exe/xmlrpc.php') diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php index d3913482f..a29a40612 100644 --- a/lib/exe/xmlrpc.php +++ b/lib/exe/xmlrpc.php @@ -7,7 +7,7 @@ if(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); /** * Increased whenever the API is changed */ -define('DOKU_XMLRPC_API_VERSION',2); +define('DOKU_XMLRPC_API_VERSION',3); require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/common.php'); @@ -118,6 +118,13 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { 'List all pages within the given namespace.' ); + $this->addCallback( + 'dokuwiki.search', + 'this:search', + array('struct','string'), + 'Perform a fulltext search and return a list of matching pages' + ); + $this->addCallback( 'dokuwiki.getTime', 'time', @@ -384,6 +391,41 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer { return $data; } + /** + * List all pages in the given namespace (and below) + */ + function search($query){ + require_once(DOKU_INC.'inc/fulltext.php'); + + $regex = ''; + $data = ft_pageSearch($query,$regex); + $pages = array(); + + // prepare additional data + $idx = 0; + foreach($data as $id => $score){ + $file = wikiFN($id); + + if($idx < FT_SNIPPET_NUMBER){ + $snippet = ft_snippet($id,$regex); + $idx++; + }else{ + $snippet = ''; + } + + $pages[] = array( + 'id' => $id, + 'score' => $score, + 'rev' => filemtime($file), + 'mtime' => filemtime($file), + 'size' => filesize($file), + 'snippet' => $snippet, + ); + } + return $data; + } + + /** * List all media files. * -- cgit v1.2.3