Files
oddmuse/contrib/grepfirstsearch.pl
Alex Schroeder 2655c0a65f 13:03 <CapnDan> sub SearchTitleAndBody {
13:04 <CapnDan> ...
13:04 <CapnDan>   foreach my $name (AllPagesSearch($string)) {
13:04 <CapnDan>     OpenPage($name);
13:04 <CapnDan> ...
2008-06-12 09:10:26 +00:00

33 lines
817 B
Perl

# #!/bin/perl
# $t = AllPagesSearch("LocalEvents") ;
sub AllPagesSearch {
my $string = shift ;
my @out ;
my %count ;
# return a list of pages that have the raw string in them according to grep
# to hand to SearchTitleAndBody
my $dir = "data/page" ;
# first search page names. Too lazy to write recursive code here - let
# ls -l do it instead of "opendir"
open(IN,"/bin/ls $dir/*/*|") ;
while (<IN>) { if (m/^.*\/(.*$string.*).pg$/i) {
#print "'" . $1 . "'\n" ;
$count{$1}++
} } ;
close(IN) ;
# now search page content
open(IN,"/opt/csw/bin/ggrep -l -i '" . $string . "' $dir/*/*|") ;
while (<IN>) {
if (m/.*\/(.*).pg/) { $count{$1}++ }
} ;
close(IN) ;
foreach (sort(keys(%count))) { push (@out,$_) } ;
return(@out) ;
} ;