2 rcs_id('$Id: FullTextSearch.php,v 1.7 2002-01-22 03:17: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();
42 while ($page = $pages->next()) {
44 $name = $page->getName();
45 $list->pushContent(HTML::dt(LinkExistingWikiWord($name)));
47 $list->pushContent($this->showhits($page, $hilight_re));
49 if (!$list->getContent())
50 $list->pushContent(HTML::dd(_("<no matches>")));
55 return array(HTML::p(fmt("Full text search results for '%s'", $s)),
59 function showhits($page, $hilight_re) {
60 $current = $page->getCurrentRevision();
61 $matches = preg_grep("/$hilight_re/i", $current->getContent());
63 foreach ($matches as $line) {
64 $line = $this->highlight_line($line, $hilight_re);
65 $html[] = HTML::dd(HTML::small(false, $line));
70 function highlight_line ($line, $hilight_re) {
71 while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) {
72 $line = substr($line, strlen($m[0]));
73 $html[] = $m[1]; // prematch
74 $html[] = HTML::strong($m[2]); // match
76 $html[] = $line; // postmatch
85 // c-hanging-comment-ender-p: nil
86 // indent-tabs-mode: nil