NYCPHP Meetup

NYPHP.org

[nycphp-talk] Search function

(Margaret) Michele Waldman mmwaldman at optonline.net
Fri Sep 19 22:02:27 EDT 2008


Thank you.  That was what I was thinking, but google I'm sure parses out the
html tags, etc, etc.

I'm pushing google to the client.

I'm betting you, that their custom search is quite more complicated.

Michele

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On
Behalf Of Steve Manes
Sent: Friday, September 19, 2008 9:59 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] Search function

(Margaret) Michele Waldman wrote:
> Does anyone know of a function or code I could use to quickly search my 
> site for a document?

If you want something permanent for your web site, this is the GNU 
successor to ht://Dig.

http://hyperestraier.sourceforge.net/

Otherwise, for shell searches I use this handy little perl script I've 
had for about 12 years.  It could be converted to a CGI script pretty 
easily (with appropriate security considerations).

#!/usr/bin/perl
# tgrep
# grep only text files (ignore binary files)
#
# Usage: tgrep [-l] pattern [files]

$nameonly = 0;

if ($ARGV[0] eq '-l') {
     $nameonly = 1;
     shift;
}

# Get pattern and protect the delimiter.
$pat = shift;
$pat =~ s/!/\\!/g;

&dodir("");

sub     dodir
{
     local($dir) = @_;
     local(@names);

     opendir(DIR, ".") || die "Can't open directory .\n";
     @names = readdir(DIR);
     closedir(DIR);

     foreach $file (@names) {
         next if $file eq '.';
         next if $file eq '..';

         if (-d $file) {
             chdir $file || die "Can't chdir to $file";
             &dodir("$dir/$file");
             chdir("..");
             next;
         }

         next if -B $file;       # Ignore binaries

         open(FILE, "<$file") || do {
             print "Can't open $file: $!\n";
             next;
         };

         while (<FILE>) {
             if ( m!$pat! ) {
                 if ($nameonly) {
                         print "$dir/$file\n";
                 }
                 else {
                         print "$dir/$file",":\t",$_;
                 }
             }
         }
         close FILE;
     }
}
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php




More information about the talk mailing list