2 rcs_id('$Id: FullTextSearch.php,v 1.9 2002-01-30 18:31:20 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 return array('s' => false,
22 // TODO: multiple page exclude
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();
44 while ($page = $pages->next()) {
46 $name = $page->getName();
47 $list->pushContent(HTML::dt($Theme->LinkExistingWikiWord($name)));
49 $list->pushContent($this->showhits($page, $hilight_re));
51 if (!$list->getContent())
52 $list->pushContent(HTML::dd(_("<no matches>")));
57 return array(HTML::p(fmt("Full text search results for '%s'", $s)),
61 function showhits($page, $hilight_re) {
62 $current = $page->getCurrentRevision();
63 $matches = preg_grep("/$hilight_re/i", $current->getContent());
65 foreach ($matches as $line) {
66 $line = $this->highlight_line($line, $hilight_re);
67 $html[] = HTML::dd(HTML::small(false, $line));
72 function highlight_line ($line, $hilight_re) {
73 while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) {
74 $line = substr($line, strlen($m[0]));
75 $html[] = $m[1]; // prematch
76 $html[] = HTML::strong($m[2]); // match
78 $html[] = $line; // postmatch
87 // c-hanging-comment-ender-p: nil
88 // indent-tabs-mode: nil