Compatible with DokuWiki
No compatibility info given!
This Syntax Plugin is a plugin that inserts the results of a search as a bulleted list of links. The list is sorted alphanumerically (natsort), and uses the correct pagenames if $conf['useheading'] is set.
To produce normal [[page]] links to found pages:
{{search>the words}}
To produce [[page#section|pagename]] links to a specified section within found pages1){{search>the words|index}}
I actually removed this “section” capability in the latest release, since it wasn't particularly useful (to me) and conflicted with searches which had a “|” in their phrases. Is this important for anyone?
For instance, {{search>searchresults}} would list the found pages as:
while {{search>searchresults "== Syntax =="|Syntax}} would list this page as:
Removed, see above.
The plugin has no configuration settings.
You may use the plugin manager to install the plugin using the links above.
To install the plugin manually, download the source to your plugin folder, “lib/plugins” and extract its contents. That will create a new plugin folder, “lib/plugins/searchresults”, and install the plugin.
<?php /** * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Todd Augsburger <todd@rollerorgans.com> */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); require_once(DOKU_INC.'inc/fulltext.php'); class syntax_plugin_searchresults extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author' => 'Todd Augsburger', 'email' => 'todd@rollerorgans.com', 'date' => '2007-08-06', 'name' => 'SearchResults Plugin', 'desc' => "returns search results as bulleted list:\n{{search>the words}} for normal [[page]] links\n{{search>the words|section}} for [[page#section|pagename]] links", 'url' => 'http://www.dokuwiki.org/plugin:searchresults', ); } function getType() { return 'substition'; } function getSort() { return 300; } function connectTo($mode) { $this->Lexer->addSpecialPattern("{{search>.*?}}", $mode, 'plugin_searchresults'); } function handle($match, $state, $pos, &$handler) { if ($state == DOKU_LEXER_SPECIAL) { // strip / from start and / from end $match = substr($match,9,-2); return array($state, $match); } return array(); } //natsort an array of pagenames function _addSorted(&$target,$names){ global $conf; if ($conf['useheading']) { // sort by headings $title_array = array(); foreach($names as $key=>$value) { if ($title = p_get_first_heading($value)) $title_array[$key] = $title; else $title_array[$key] = $value; } natsort($title_array); foreach($title_array as $key=>$value) $target[] = $names[$key]; } else { // sort by pagenames natsort($names); foreach($names as $value) $target[] = $value; } } function render($mode, &$renderer, $data) { if ($mode == 'xhtml') { list($state, $match) = $data; if ($state == DOKU_LEXER_SPECIAL) { $matches = array(); if(preg_match('/(.*)\|(.*)/',$match,$matches)) $search = ft_pageSearch($matches[1],$poswords); else $search = ft_pageSearch($match,$poswords); if(count($search)){ $renderer->doc .= "<ul>\n"; $key_array = array(); $this->_addSorted($key_array,array_keys($search)); foreach($key_array as $value) { $renderer->doc .= '<li class="level1"><div class="li">'; if(empty($matches[2])) $renderer->doc .= html_wikilink(':'.$value); else $renderer->doc .= html_wikilink(':'.$value.'#'.$matches[2],($title = p_get_first_heading($value)) ? $title : $value); $renderer->doc .= "</div>\n"; } $renderer->doc .= "</ul>\n"; } } return true; } return false; } }
Thanks for making this available. I got it installed and it mostly does what I want, but…
It seems to be missing:
require_once(DOKU_INC.'inc/fulltext.php');
Correct! I'll update the code.
Also, a few other things would be nice:
I use the ~~NOCACHE~~ tag in pages which need to be updated “realtime”
I use ”@namespace” within my searches to limit them to a single namespace …
and do multiple searches for multiple criteria–that way it's not limited to just namespaces
So, using the above, I put the namespaces or descriptions on the page. Tables work well, too.
Agreed. My “work-around” is that I use another plugin which allows tags in the page, so my searches exclude certain tags
Well, not always–I want my “lists” to be identical everywhere. But it might make a good option
Good suggestion
Hi Todd. Superb plugin - it makes multiple relationships between pages really easy to do.
However, I WOULD like the section search facility. Why?
My site has lists of tunes, and I would like to link to tune authors.
But I do sometimes refer to the same people as playing those tunes. Obviously, this would cause doubles where I don't want them.
However, since I will put tune authors in a separate section, this would work.
Could you maybe just quote the necessary code here? I could then just paste it in and you would not need to do a new release.
Cheers
The original code (which included the ability to go to a section) is what is still shown above
Note that it did not “search” for the section, it simply allowed the section text to be specified and passed to the resultant HTML. i.e. …
{{search>the words|section}}returned a link like
[[page#section|pagename]]