2 rcs_id('$Id: FullTextSearch.php,v 1.5 2002-01-10 23:23:39 carstenklapp 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 // FIXME: how to exclude multiple pages?
21 return array('s' => false,
26 function run($dbi, $argstr, $request) {
28 $args = $this->getArgs($argstr, $request);
29 if (empty($args['s']))
34 $query = new TextSearchQuery($s);
35 $pages = $dbi->fullSearch($query);
37 $hilight_re = $query->getHighlightRegexp();
41 while ($page = $pages->next()) {
43 $name = $page->getName();
44 $lines[] = Element('dt', LinkExistingWikiWord($name));
46 $lines[] = $this->showhits($page, $hilight_re);
51 $html .= QElement('p',
52 sprintf(_("Full text search results for '%s'"), $s));
54 $lines[] = QElement('dd', _("<no matches>"));
56 $html .= Element('dl', join("\n", $lines));
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 .= Element('dd', Element('small', $line)) . "\n";
81 // c-hanging-comment-ender-p: nil
82 // indent-tabs-mode: nil