2 rcs_id('$Id: FullTextSearch.php,v 1.6 2002-01-21 06:55:47 dairiki Exp $');
4 require_once('lib/TextSearchQuery.php');
8 class WikiPlugin_FullTextSearch
12 return _("FullTextSearch");
15 function getDescription () {
16 return _("Full Text Search");
19 function getDefaultArguments() {
20 return array('s' => false,
25 function run($dbi, $argstr, $request) {
27 $args = $this->getArgs($argstr, $request);
28 if (empty($args['s']))
33 $query = new TextSearchQuery($s);
34 $pages = $dbi->fullSearch($query);
36 $hilight_re = $query->getHighlightRegexp();
43 while ($page = $pages->next()) {
45 $name = $page->getName();
46 $list->pushContent(HTML::dt($Theme->linkExistingWikiWord($name)));
48 $list->pushContent($this->showhits($page, $hilight_re));
50 if (!$list->getContent())
51 $list->pushContent(HTML::dd(_("<no matches>")));
56 return array(HTML::p(fmt("Full text search results for '%s'", $s)),
60 function showhits($page, $hilight_re) {
61 $FS = &$GLOBALS['FieldSeparator'];
62 $current = $page->getCurrentRevision();
63 $matches = preg_grep("/$hilight_re/i", $current->getContent());
65 foreach ($matches as $line) {
66 $line = str_replace($FS, '', $line);
67 $line = preg_replace("/$hilight_re/i", "${FS}OT\\0${FS}CT", $line);
68 $line = htmlspecialchars($line);
69 $line = str_replace("${FS}OT", '<strong>', $line);
70 $line = str_replace("${FS}CT", '</strong>', $line);
71 $html[] = HTML::dd(HTML::small(new RawXml($line)));
81 // c-hanging-comment-ender-p: nil
82 // indent-tabs-mode: nil