2 rcs_id('$Id: FullTextSearch.php,v 1.16 2004-02-17 12:11:36 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 require_once('lib/TextSearchQuery.php');
27 class WikiPlugin_FullTextSearch
31 return _("FullTextSearch");
34 function getDescription() {
35 return _("Search the content of all pages in this wiki.");
38 function getVersion() {
39 return preg_replace("/[Revision: $]/", '',
40 "\$Revision: 1.16 $");
43 function getDefaultArguments() {
44 return array('s' => false,
46 // TODO: multiple page exclude
50 function run($dbi, $argstr, &$request, $basepage) {
52 $args = $this->getArgs($argstr, $request);
53 if (empty($args['s']))
58 $query = new TextSearchQuery($s);
59 $pages = $dbi->fullSearch($query);
61 $hilight_re = $query->getHighlightRegexp();
67 while ($page = $pages->next()) {
69 $name = $page->getName();
70 $list->pushContent(HTML::dt(WikiLink($name)));
72 $list->pushContent($this->showhits($page, $hilight_re));
74 if (!$list->getContent())
75 $list->pushContent(HTML::dd(_("<no matches>")));
80 return HTML(HTML::p(fmt("Full text search results for '%s'", $s)),
84 function showhits($page, $hilight_re) {
85 $current = $page->getCurrentRevision();
86 $matches = preg_grep("/$hilight_re/i", $current->getContent());
88 foreach ($matches as $line) {
89 $line = $this->highlight_line($line, $hilight_re);
90 $html[] = HTML::dd(HTML::small(array('class' => 'search-context'),
96 function highlight_line ($line, $hilight_re) {
97 while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) {
98 $line = substr($line, strlen($m[0]));
99 $html[] = $m[1]; // prematch
100 $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match
102 $html[] = $line; // postmatch
107 // $Log: not supported by cvs2svn $
108 // Revision 1.15 2003/01/18 21:41:01 carstenklapp
110 // Reformatting & tabs to spaces;
111 // Added copyleft, getVersion, getDescription, rcs_id.
118 // c-hanging-comment-ender-p: nil
119 // indent-tabs-mode: nil