--- Search.pm.orig 2008-05-26 11:05:24.000000000 +0200 +++ Search.pm.mod 2008-05-26 11:27:12.000000000 +0200 @@ -580,6 +580,8 @@ my $query; my @tokens; + my $searchExpression; + my $searchEscaped; if( $type eq 'query' ) { unless( defined( $queryParser )) { @@ -598,6 +600,9 @@ # Split the search string into tokens depending on type of search - # each token is ANDed together by actual search @tokens = _tokensFromSearchString( $this, $searchString, $type ); + $searchExpression = join("|" , @tokens); + $searchEscaped = join("\%VBAR\%", @tokens); + return '' unless scalar(@tokens); } @@ -891,8 +896,10 @@ s/\$parent\(([^\)]*)\)/TWiki::Render::breakName( $meta->getParent(), $1 )/ges; $out =~ s/\$parent/$meta->getParent()/ges; $out =~ s/\$formname/$meta->getFormName()/ges; - $out =~ - s/\$count\((.*?\s*\.\*)\)/_countPattern( $text, $1 )/ges; + # CLIF: modified count, added two lines to return search pattern or count in context + $out =~ s/\$count\((.*?\s*\.\*)\)/_countPattern( $text, $1, $caseSensitive )/ges; + $out =~ s/\$searchpattern/$searchEscaped/gs; + $out =~ s/\$countcontext\(\(([^)]*)\)\(([^)]*)\)\)/_countPattern( $text, ".*?${1}($searchExpression)${2}.*", $caseSensitive)/ges; # FIXME: Allow all regex characters but escape them # Note: The RE requires a .* at the end of a pattern to avoid false positives @@ -1216,7 +1223,7 @@ # With the same argument as $pattern, returns a number which is the count of # occurences of the pattern argument. sub _countPattern { - my ( $theText, $thePattern ) = @_; + my ( $theText, $thePattern, $caseSensitive ) = @_; $thePattern =~ s/([^\\])([\$\@\%\&\#\'\`\/])/$1\\$2/go; # escape some special chars @@ -1224,9 +1231,12 @@ $thePattern = $1; my $OK = 0; eval { - # counting hack, see: http://dev.perl.org/perl6/rfc/110.html - $OK = () = $theText =~ /$thePattern/g; + if ($caseSensitive) { + $OK = () = $theText =~ /$thePattern/g; + } else { + $OK = () = $theText =~ /$thePattern/gi; + } }; return $OK;