Table of Contents
searchresults plugin
Compatible with DokuWiki
No compatibility info given!
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
This plugin is discontinued as according to his website (2012-06-29) the author of this plugin died in 2011. Feel free to adopt the plugin.
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.
Syntax
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.
Configuration
The plugin has no configuration settings.
Installation
Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.
- Development: zip file 2007-02-27
Revision History
- 2007-08-30 — Updated.
- 2007-08-06 — Updated.
- 2007-02-27 — Released.
syntax.php
<?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; } }
Tips
- Or in use (in an open wiki) here
Discussion
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:
- the search results don't update without setting the cache time to something short for the entire wiki; it would be nice if that wasn't necessary
I use the ~~NOCACHE~~ tag in pages which need to be updated “realtime”
- it would be nice to be able to include/exclude namespaces
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
- it would be nice to be able to display the namespace in the search results
So, using the above, I put the namespaces or descriptions on the page. Tables work well, too.
- it would be nice to be able to exclude specific pages
Agreed. My “work-around” is that I use another plugin which allows tags in the page, so my searches exclude certain tags
- the page containing the search should probably always be excluded
Well, not always–I want my “lists” to be identical everywhere. But it might make a good option
- it would be nice to be able to display context optionally
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]]