#!/usr/local/bin/perl $basedir = '/home/autoped/public_html/html/'; $baseurl = 'http://autopedia.com/html/'; @files = ('*.html','AutomotiveClubs/*.html'); $summary_file = '/home/autoped/public_html/logs/summaries.html'; $link_url = 'http://autopedia.com/'; $link_title = 'AUTOPEDIA - The Automotive Encyclopedia'; $java_toys = 'on'; $searchpict = 'http://autopedia.com/Graphics/search.gif'; $cgi_url = 'http://autopedia.com/cgi-bin/APIIsearch.cgi'; ($name_x, $title_x, $keywords_x, $description_x) = (2,2,0,2); # __________________________________________________________________ read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name,$value) = split(/=/,$pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } if ($FORM{'terms'}) { &get_files; &search; &return_html; } else { &prompt; } sub prompt { print "Content-type: text/html\n\n"; print < AUTOPEDIA™: Search Our Site


Enter a few keywords or read our search tips below to make advanced queries.

EOM if ($java_toys eq 'on') { print "\n"; } print <

Advanced Searching Tips...

Each term may be preceded by the standard Boolean operators not, and, or or. If you search for "trucks not ford", you'll find all documents containing the word "trucks" except those documents which also contain the word "ford". If you type in "and trucks and ford and chevy", you'll find only those documents which contain all three search terms. The default value is or. A regular search for "chevy ford truck" would return pages with at least one of the three terms.

Shorthand notation will also work. A search on "truck -ford" is equivalent to the first example above, and "+truck +ford +chevy" will return the same documents as the second.

If you enter a search term with at least one capital letter, like "Stores", the search will be case sensitive with respect to that word - otherwise lowercase words like "stores" will generate hits from "Stores", "STORES", or "StoreS".

To group a collection of words, use quotes. For example, the query "Chevrolet Corvette" (quotes included) would not generate a hit from "Corvette by Chevrolet". Without quotes, the sentence would count. Boolean operators can also act on quotations: a search on '+Chevrolet +Corvette not "Chevrolet Corvette"' would return only those documents where "Chevrolet" and "Corvette" appear separately.

To perform a string search, preface your term with the dollar sign - a query on "\$in" would find all words containing "in". Complex wildcard searches using the asterisk are NOT permitted.



[email image]
Last modified 10/02/97. Copyright ©1995-97 by AUTOPEDIA, all rights reserved. AUTOPEDIA™, AUTO411™, CAR-IQ™, DEALERPEDIA™, INTERLOT™, SIMULSEARCH™ and INTERQUOTE-RFP™ are trademarks of AUTOPEDIA. All other trademarks, tradenames and/or service marks are the property of their respective holders. EOM } sub get_files { &bad_base unless (-e $basedir); chdir($basedir); foreach $file (@files) { $ls = `ls $file`; @ls = split(/\s+/,$ls); foreach $temp_file (@ls) { if (-d $file) { $filename = "$file$temp_file"; if (-T $filename) { push(@FILES,$filename); } } elsif (-T $temp_file) { push(@FILES,$temp_file); } } } } sub search { $FORM{'terms'} =~ s/\s+/ /g; $FORM{'terms'} = " $FORM{'terms'} "; $FORM{'terms'} =~ s/ not / -/ig; $FORM{'terms'} =~ s/ and / \+/ig; $FORM{'terms'} =~ s/ or / /ig; $check = 'true' unless ($FORM{'terms'} =~ /\*/); @terms = split(/\"/,$FORM{'terms'}); $iterator = 0; $FORM{'terms'} = ""; $placeholder = '%%%==%%%'; foreach $term (@terms) { # Do some binary-state switching: if ($iterator == 1) {$iterator--;} else {$iterator++;} # The iterator is 0 during grouped states: $term =~ s/ /$placeholder/g unless $iterator; $FORM{'terms'} .= $term; } @terms = split(/\s+/,$FORM{'terms'}); foreach $term (@terms) { # Skip null entries (first and last) next if ($term eq ''); # Unmask grouped terms: $term =~ s/$placeholder/ /g; if ($term =~ /^\+/) { $term =~ s/\+//o; $term = '\W' . $term. '\W' unless ($term =~ /^\$/); $term =~ s/^\$//; push(@required,$term); $required_terms_present = "you bet"; } elsif ($term =~ /^-/) { $term =~ s/-//o; $term = '\W' . $term. '\W' unless ($term =~ /^\$/); $term =~ s/^\$//; push(@forbidden,$term); $forbidden_terms_present = "fraid so"; } else { $term = '\W' . $term. '\W' unless ($term =~ /^\$/); $term =~ s/^\$//; push(@optional,$term); } } foreach $FILE (@FILES) { open(FILE,"$FILE"); @LINES = ; close(FILE); $string = join(' ',@LINES); $string =~ s/\n//g; if ($string =~ /(.*)<\/title>/i) { $titles{$FILE} = $1; for ($i=1;$i<$title_x;$i++) { $string .= $titles{$FILE}; } } $titles{$FILE} = $FILE unless $titles{$FILE}; if ($string =~ /<meta\s+name="description"\s+content="(.*)>/i) { @cut = split(/\">/,$1); $description{$FILE} = $cut[0]; for ($i=0;$i<$description_x;$i++) { $string .= $description{$FILE}; } } else { $string2 = $string; $string2 =~ s/<title>(.*)<\/title>//ig; $string2 =~ s/<([^>]|\n)*>//g; @words = split(/\s+/,$string2); for ($i=0;$i<25;$i++) {$description{$FILE} .= "$words[$i] ";} $description{$FILE} .= "..."; } if ($string =~ /<meta\s+name="keywords"\s+content="(.*)>/i) { @cut = split(/\">/,$1); $keywords = $cut[0]; for ($i=0;$i<$keywords_x;$i++) { $string .= $keywords; } } for ($i=0;$i<$name_x;$i++) { $string .= "$baseurl$FILE"; } $string =~ s/<([^>]|\n)*>//g; foreach $term (@optional) { $lowercase = $term; $lowercase =~ tr/[A-Z]/[a-z]/; $lowercase =~ tr/\\w/\\W/; if (($term eq $lowercase) && ($check)) { $include{$FILE} = 'yes' if ($string =~ /$term/i); @count = split(/$term/i,$string); } elsif ($check) { $include{$FILE} = 'yes' if ($string =~ /$term/); @count = split(/$term/,$string); } $word_count = @count; $relevance{$FILE} = $relevance{$FILE} + $word_count; } if ($required_terms_present eq "you bet") { foreach $term (@required) { $lowercase = $term; $lowercase =~ tr/[A-Z]/[a-z]/; $lowercase =~ tr/\\w/\\W/; if (($term eq $lowercase) && ($check)) { if (($string =~ /$term/i) && ($include{$FILE} ne 'no')) { $include{$FILE} = 'yes'; @count = split(/$term/i,$string); } else { $include{$FILE} = 'no'; last; } } elsif ($check) { if (($string =~ /$term/) && ($include{$FILE} ne 'no')) { $include{$FILE} = 'yes'; @count = split(/$term/,$string); } else { $include{$FILE} = 'no'; last; } } $word_count = @count; $relevance{$FILE} = $relevance{$FILE} + $word_count; } } if (($forbidden_terms_present eq "fraid so") && ($check)) { foreach $term (@forbidden) { $lowercase = $term; $lowercase =~ tr/[A-Z]/[a-z]/; $lowercase =~ tr/\\w/\\W/; if (($term eq $lowercase) && ($string =~ /$term/i)) { $include{$FILE} = 'no'; last; } elsif ($string =~ /$term/) { $include{$FILE} = 'no'; last; } } } $include{$FILE} = 'yes' unless ($check); if ($include{$FILE} eq 'yes') { $relevance = sprintf("%.3f",($relevance{$FILE}/1000)); $HITS{"$relevance$FILE"} = "$FILE"; $hitcount++; } } # End loop through all files. } # End search procedure. sub return_html { $docstring = "$hitcount Documents"; $docstring = "One Document" if ($hitcount == 1); $docstring = "No Documents" unless ($hitcount); $summary = "<CENTER><FONT SIZE=5><B>Search Results: $docstring Found</B></FONT>\n"; $summary .= "<BLOCKQUOTE>\n<PRE>\n"; $summary .= " Optional Terms: " if (@optional); $i = 0; foreach $term (@optional) { $term = "<I>$term</I>" unless ($term =~ /^\\W/); $term =~ s/\\W//g; $summary .= "$term"; $i++; $summary .= ", " unless ($i == @optional); } $summary .= "\n Required Terms: " if (@required); $i = 0; foreach $term (@required) { $term = "<I>$term</I>" unless ($term =~ /^\\W/); $term =~ s/\\W//g; $summary .= "$term"; $i++; $summary .= ", " unless ($i == @required); } $summary .= "\n Forbidden Terms: " if (@forbidden); $i = 0; foreach $term (@forbidden) { $term = "<I>$term</I>" unless ($term =~ /^\\W/); $term =~ s/\\W//g; $summary .= "$term"; $i++; $summary .= ", " unless ($i == @forbidden); } $summary .= "\n</PRE></BLOCKQUOTE></CENTER><HR SIZE=3>\n"; open(SUMMARY,">>$summary_file"); print SUMMARY "Search by $ENV{'REMOTE_HOST'}:<BR>\n"; print SUMMARY $summary; close(SUMMARY); print "Content-type: text/html\n\n"; print <<EOM; <HTML> <HEAD><TITLE>AUTOPEDIA™: Search Results

$summary

EOM if ($hitcount > 0) { foreach $key (reverse sort keys %HITS) { $file = $HITS{$key}; $size = -s "$basedir$file"; if ($size > 1500) {$size = int($size/1000) . " K";} else {$size = "$size bytes";} $last = &Last_Modified("$basedir$file"); print "

$titles{$file}
\n"; print "
$description{$file}
\n"; print "$baseurl$file"; print " - $size - $last
\n"; } } else { print <Sorry, we didn't find any documents that matched your search terms. You may want to visit our search tips page to refine your queries.
EOM } print <



Search Tips

[email image]
Last modified 10/02/97. Copyright ©1995-97 by AUTOPEDIA, all rights reserved. AUTOPEDIA™, AUTO411™, CAR-IQ™, DEALERPEDIA™, INTERLOT™, SIMULSEARCH™ and INTERQUOTE-RFP™ are trademarks of AUTOPEDIA. All other trademarks, tradenames and/or service marks are the property of their respective holders. EOM } sub Last_Modified { $filename = shift; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime((stat($filename))[9]); @months = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec); return "$mday $months[$mon] $year"; } sub bad_base { print "Content-type: text/html\n\n"; print "I tried to find the base directory you specified:\n"; print "
$basedir
\n"; print "But the system told me that it did not exist.\n"; exit; }