====== searchresults plugin ====== ---- plugin ---- description: List of page links from search criteria author : Todd Augsburger email : type : syntax lastupdate : 2007-08-06 compatible : depends : conflicts : similar : tags : search, listing, include, !discontinued downloadurl: http://cobs.rollerorgans.com/plugins/searchresults.zip ---- :!: This plugin is discontinued as according to [[http://rollerorgans.com/|his website (2012-06-29)]] the author of this plugin died in 2011. Feel free to [[devel:adoption|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['[[config: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 pages((There is __no__ error checking on whether these sections actually exist--this is most useful when the section are also part of the search criteria.)) {{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: *[[:plugins]] *[[plugin:searchresults]] > while %%{{search>searchresults "== Syntax =="|Syntax}}%% would list this page as: *[[plugin:searchresults#Syntax|searchresults]] > Removed, see above. ===== Configuration ===== The plugin has no configuration settings. ===== Installation ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. * Development: [[http://cobs.rollerorgans.com/plugins/searchresults.zip|zip file]] 2007-02-27 ===== Revision History ===== * 2007-08-30 --- Updated. * 2007-08-06 --- Updated. * 2007-02-27 --- Released. ===== syntax.php ===== */ 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 .= "\n"; } } return true; } return false; } } ===== Tips ===== *You may see the searchresults plugin in use (in a closed wiki) [[http://cobs.rollerorgans.com/cobs/2/home|here]] where a [[plugin:folded|folded]] list is presented.\\ (Click on the "Composer"--the wiki syntax is %%{{search>"Lowell Mason" @cobs}}%%) *Or in use (in an open wiki) [[http://wiki.mechanicalmusic.info/scales/home|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 [[http://www.tunemason.org|Ed Bradburn]] > 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]] [[todd@rollerorgans.com|Todd Augsburger 2008-10-17]]