2 rcs_id('$Id: FullTextSearch.php,v 1.1 2001-09-18 19:19:05 dairiki Exp $');
4 require_once('lib/TextSearchQuery.php');
8 class WikiPlugin_FullTextSearch
11 var $name = 'FullTextSearch';
13 function getDefaultArguments() {
14 // FIXME: how to exclude multiple pages?
15 return array('s' => false,
19 function getDefaultFormArguments() {
20 $defaults = parent::getDefaultFormArguments();
21 $defaults['description'] = gettext('Full Text Search');
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();
40 while ($page = $pages->next()) {
42 $name = $page->getName();
43 $lines[] = Element('dt', LinkExistingWikiWord($name));
45 $lines[] = $this->showhits($page, $hilight_re);
50 $html .= QElement('p',
51 sprintf(gettext("Full text search results for '%s'"), $s));
53 $lines[] = QElement('dd', gettext("<no matches>"));
55 $html .= Element('dl', join("\n", $lines));
59 function showhits($page, $hilight_re) {
60 $FS = &$GLOBALS['FieldSeparator'];
61 $current = $page->getCurrentRevision();
62 $matches = preg_grep("/$hilight_re/i", $current->getContent());
64 foreach ($matches as $line) {
65 $line = str_replace($FS, '', $line);
66 $line = preg_replace("/$hilight_re/i", "${FS}OT\\0${FS}CT", $line);
67 $line = htmlspecialchars($line);
68 $line = str_replace("${FS}OT", '<b>', $line);
69 $line = str_replace("${FS}CT", '</b>', $line);
70 $html .= Element('dd', Element('small', $line)) . "\n";
75 function make_form($args) {
76 // FIXME: need more thought about this whole interface.
77 $args['search'] = '()';
78 return MakeWikiForm($GLOBALS['pagename'], $args, 'wikiaction','Full Text Search');
86 // c-hanging-comment-ender-p: nil
87 // indent-tabs-mode: nil