*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_INC.'inc/parser/parser.php');
require_once(DOKU_PLUGIN . 'action.php');
require_once(DOKU_PLUGIN . 'sphinxsearch/sphinxapi.php');
require_once(DOKU_PLUGIN . 'sphinxsearch/PageMapper.php');
require_once(DOKU_PLUGIN . 'sphinxsearch/SphinxSearch.php');
require_once(DOKU_PLUGIN . 'sphinxsearch/functions.php');
class action_plugin_sphinxsearch extends DokuWiki_Action_Plugin {
var $_search = null;
var $_helpMessage = '';
var $_versionNumber = '0.3.6';
/**
* return some info
*/
function getInfo() {
return confToHash(dirname(__FILE__).'/plugin.info.txt');
}
function getHelpInfo(){
$this->_helpMessage = "
===== DokuWiki Sphinx Search plugin features=====
To use the search you need to just enter your search keywords into the searchbox at the top right corner of the DokuWiki. When basic simple search is not enough you can try using the methods listed below:
=== Phrase search (\"\") ===
Put double quotes around a set of words to enable phrase search mode. For example:
\"James Bond\"
=== Search within a namespace ===
You can add \"@ns\" parameter to limit the search to some namespace. For exapmle:
hotel @ns personal:mike:travel
Such query will return only results from \"personal:mike:travel\" namespace for keyword \"hotel\".
=== Excluding keywords or namespaces from search ===
You can add a minus sign to a keyword or a category name exclude it from search. For example:
hotel @ns -personal:mike
Such query will look for \"hotel\" everywhere except the \"personal:mike\" namespace.
blog -post
Such query will look for documents that have keyword \"blog\" but don't have keyword \"post\".
===== =====
DokuWiki Sphinx Search plugin (version $this->_versionNumber) by [[http://www.ivinco.com/software/dokuwiki-sphinx-search-plugin/|Ivinco]].
";
return $this->_helpMessage;
}
/**
* Register to the content display event to place the results under it.
*/
/**
* register the eventhandlers
*/
function register(&$controller){
$controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, 'handle_act_unknown', array());
}
/**
* If our own action was given we produce our content here
*/
function handle_act_unknown(&$event, $param){
global $ACT;
global $QUERY;
if($ACT != 'search') return; // nothing to do for us
// we can handle it -> prevent others
$event->stopPropagation();
$event->preventDefault();
/* if (!extension_loaded('sqlite')) {
echo "SQLite extension is not loaded!";
return;
}*/
if(!empty($_REQUEST['ssplugininfo'])){
$info = array();
echo p_render('xhtml',p_get_instructions($this->getHelpInfo()), $info);
return;
}
$this->_search($QUERY,$_REQUEST['start'],$_REQUEST['prev']);
}
/**
* do the search and displays the result
*/
function _search($query, $start, $prev) {
global $conf;
$start = (int) $start;
if($start < 0){
$start = 0;
}
if(empty($prev)){
$prev = 0;
}
$categories = $this->_getCategories($query);
$keywords = $this->_getKeywords($query);
$search = new SphinxSearch($this->getConf('host'), $this->getConf('port'), $this->getConf('index'));
$search->setSnippetSize($this->getConf('snippetsize'));
$search->setArroundWordsCount($this->getConf('aroundwords'));
$search->setTitlePriority($this->getConf('title_priority'));
$search->setBodyPriority($this->getConf('body_priority'));
$search->setNamespacePriority($this->getConf('namespace_priority'));
$search->setPagenamePriority($this->getConf('pagename_priority'));
if (!empty($keywords) && empty($categories)){
$search->setSearchAllQuery($keywords, $categories);
} elseif (!empty($keywords)) {
$search->setSearchAllQueryWithCategoryFilter($keywords, $categories);
} else {
echo 'Your search - ' . $query . ' - did not match any documents.
Search help';
return;
}
$result = $search->search($start, $this->getConf('maxresults'));
$this->_search = $search;
if ($search->getError()){
echo "Could not connect to Sphinx search engine.";
return;
}
if(!$result){
echo 'Your search - ' . $query . ' - did not match any documents.
Search help';
return;
}
$pagesList = $search->getPages($keywords);
$totalFound = $search->getTotalFound();
if(empty($pagesList) || 0 == $totalFound){
echo 'Your search - ' . $query . ' - did not match any documents.
Search help';
return;
} else {
echo '
';
echo '