2 rcs_id('$Id: FullTextSearch.php,v 1.11 2002-02-01 21:59:59 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,
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();
43 while ($page = $pages->next()) {
45 $name = $page->getName();
46 $list->pushContent(HTML::dt(WikiLink($name)));
48 $list->pushContent($this->showhits($page, $hilight_re));
50 if (!$list->getContent())
51 $list->pushContent(HTML::dd(_("<no matches>")));
56 return HTML(HTML::p(fmt("Full text search results for '%s'", $s)),
60 function showhits($page, $hilight_re) {
61 $current = $page->getCurrentRevision();
62 $matches = preg_grep("/$hilight_re/i", $current->getContent());
64 foreach ($matches as $line) {
65 $line = $this->highlight_line($line, $hilight_re);
66 $html[] = HTML::dd(HTML::small(false, $line));
71 function highlight_line ($line, $hilight_re) {
72 while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) {
73 $line = substr($line, strlen($m[0]));
74 $html[] = $m[1]; // prematch
75 $html[] = HTML::strong($m[2]); // match
77 $html[] = $line; // postmatch
86 // c-hanging-comment-ender-p: nil
87 // indent-tabs-mode: nil