I have created a 'quiet' option for FullTextSearch, to allow one to
display either the page name alone (a la BackLinks) or the context,
as it currently does.
Just add
<?plugin FullTextSearch s="TermOne TermTwo -TermThree" quiet=1 ?>
and the result will be
* PageNameOne
* PageNameTwo
* PageNameThree
* PageNameFour
Just like BackLinks.
This is useful, because it allows a similar 'clean' presentation to
BackLinks, with the added functionality of allowing multiple keywords.
Thanks,
Micki
a simple diff/code snippet is below:
lib/plugin/FullTextSearch.php
- add 'quiet' option
THE DIFF
44a45
> 'quiet' => false,
64a66,67
> if (!$quiet)
> {
66c69,74
<
---
> }
> else
> {
> $list = HTML::ul();
> }
> ;
69a78,83
> if ($quiet)
> {
> $list->pushContent(HTML::li(WikiLink($name)));
> }
> else
> {
70a85,89
>
> }
> ;
> if (!$quiet)
> {
72a92,93
> };
>
THE FULL CODE
function getDefaultArguments() {
return array('s' => false,
'noheader' => false,
'quiet' => false);
// TODO: multiple page exclude
}
function run($dbi, $argstr, $request) {
$args = $this->getArgs($argstr, $request);
if (empty($args['s']))
return '';
extract($args);
$query = new TextSearchQuery($s);
$pages = $dbi->fullSearch($query);
$lines = array();
$hilight_re = $query->getHighlightRegexp();
$count = 0;
$found = 0;
if (!$quiet)
{
$list = HTML::dl();
}
else
{
$list = HTML::ul();
}
;
while ($page = $pages->next()) {
$count++;
$name = $page->getName();
if ($quiet)
{
$list->pushContent(HTML::li(WikiLink($name)));
}
else
{
$list->pushContent(HTML::dt(WikiLink($name)));
}
;
if (!$quiet)
{
if ($hilight_re)
$list->pushContent($this->showhits($page, $hilight_re));
};
}
if (!$list->getContent())
$list->pushContent(HTML::dd(_("<no matches>")));
if ($noheader)
return $list;
return HTML(HTML::p(fmt("Full text search results for '%s'", $s)),
$list);
}
function showhits($page, $hilight_re) {
$current = $page->getCurrentRevision();
$matches = preg_grep("/$hilight_re/i", $current->getContent());
$html = array();
foreach ($matches as $line) {
$line = $this->highlight_line($line, $hilight_re);
$html[] = HTML::dd(HTML::small(array('class' =>
'search-context'), $line));
}
return $html;
}
function highlight_line ($line, $hilight_re) {
while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) {
$line = substr($line, strlen($m[0]));
$html[] = $m[1]; // prematch
$html[] = HTML::strong(array('class' => 'search-term'),
$m[2]); // match
}
$html[] = $line; // postmatch
return $html;
}
};
--
Micki
mailto:mic...@co...
|