2 // Search the text of pages for a match.
3 rcs_id('$Id: fullsearch.php,v 1.7 2001-09-18 19:16:23 dairiki Exp $');
4 require_once('lib/Template.php');
5 require_once('lib/TextSearchQuery.php');
7 $query = new TextSearchQuery($args->get('searchterm'));
10 . sprintf(gettext ("Searching for \"%s\" ....."),
11 htmlspecialchars($args->get('searchterm')))
12 . "</b></p>\n<dl>\n" );
14 // search matching pages
15 $iter = $dbi->fullsearch($query);
17 // quote regexp chars (space are treated as "or" operator)
18 $hilight_re = $query->getHighlightRegexp();
22 while ($page = $iter->next()) {
23 $html .= "<dt><b>" . LinkExistingWikiWord($page->getName()) . "</b>\n";
25 if (empty($hilight_re))
26 continue; // nothing to highlight
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",
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";
45 $html .= ( "</dl>\n<hr noshade>"
46 . sprintf (gettext ("%d matches found in %d pages."),
50 echo GeneratePage('MESSAGE', $html, sprintf(gettext("Full Text Search: %s"), $searchterm));