]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/fullsearch.php
Fix SF bug #473493: Need to include lib/template.php before calling
[SourceForge/phpwiki.git] / lib / fullsearch.php
1 <?php
2 // Search the text of pages for a match.
3 rcs_id('$Id: fullsearch.php,v 1.8 2001-09-19 03:24:36 wainstead Exp $');
4 require_once('lib/Template.php');
5 require_once('lib/TextSearchQuery.php');
6
7 $query = new TextSearchQuery($args->get('searchterm'));
8
9 $html = ("<p><b>"
10          . sprintf(gettext ("Searching for \"%s\" ....."),
11                    htmlspecialchars($args->get('searchterm')))
12          . "</b></p>\n<dl>\n" );
13
14 // search matching pages
15 $iter = $dbi->fullsearch($query);
16
17 // quote regexp chars (space are treated as "or" operator)
18 $hilight_re = $query->getHighlightRegexp();
19
20 $found = 0;
21 $count = 0;
22 while ($page = $iter->next()) {
23     $html .= "<dt><b>" . LinkExistingWikiWord($page->getName()) . "</b>\n";
24     $count++;
25     if (empty($hilight_re))
26         continue;               // nothing to highlight
27     
28     // print out all matching lines, highlighting the match
29     $current = $page->getCurrentRevision();
30     $matches = preg_grep("/$hilight_re/i", $current->getContent());
31     foreach ($matches as $line) {
32         if ($hits = preg_match_all("/$hilight_re/i", $line, $dummy)) {
33             $line = preg_replace("/$hilight_re/i",
34                                  "${FieldSeparator}OT\\0${FieldSeparator}CT",
35                                  $line);
36             $line = htmlspecialchars($line);
37             $line = str_replace("${FieldSeparator}OT", '<b>', $line);
38             $line = str_replace("${FieldSeparator}CT", '</b>', $line);
39             $html .= "<dd><small>$line</small></dd>\n";
40             $found += $hits;
41         }
42     }
43 }
44
45 $html .= ( "</dl>\n<hr noshade>"
46            . sprintf (gettext ("%d matches found in %d pages."),
47                       $found, $count)
48            . "\n");
49            
50 echo GeneratePage('MESSAGE', $html, sprintf(gettext("Full Text Search: %s"), $searchterm));
51
52
53 // For emacs users
54 // Local Variables:
55 // mode: php
56 // tab-width: 8
57 // c-basic-offset: 4
58 // c-hanging-comment-ender-p: nil
59 // indent-tabs-mode: nil
60 // End:
61
62 ?>