поиск по сайту
Hi!
Для организации поиска по сайту нашел в инете скрипт на Perl (find.pl и dirscan.pl),
find.pl
#!/usr/local/bin/perl
###################################
## K.I.S.S. Site Search Engine
## scripted by Alexander Moskalyuk
## http://www.moskalyuk.com
###################################
use CGI;
#this is the address of your main directory
#(directory where you want to start searching)
#on the Unix machine
$basedir="/data1/virtualave.net/username/public_html";
#This is the main URL of your site
$baseurl="http://home.infocity.de/almen/AFW/index.htm";
#Here's the list of all the files to be searched during the search
$fileinfo="$basedir/search/fileinfo.txt";
#Provide header and footer for nicer output
$headerfile="$basedir/search/header.txt";
$footerfile="$basedir/search/footer.txt";
print "Content-type: text/html\n\n";
getString(); #get the CGI string
getFiles(); #get the list of files to scan
search(); #do it!
print_header(); #print the header
results(); #insert the results of the search
print_footer(); #print the footer
###################################################################### ###
sub getFiles
{
open (FILEINFO, "<$fileinfo") || die "No such file";
my $counter=0;
while (<FILEINFO>)
{
chomp($_);
push (@files, $_);#push every filename onto array
$points[$counter++]=0;#no points assigned to the file originally
}#end of while
close (FILEINFO);
}#end of getFiles
###################################################################### ###
sub getString
{
my $a=new CGI;
my $str=$a->param('string'); #just one parameter
$str= lc $str; #all to lowercase
@string = split (/ /, $str); #split on whitespace
}
###################################################################### ###
sub search
{
foreach $search_word (@string)
{
my $counter=0;
foreach $file_name (@files)
{
open (FILE, "<$basedir$file_name");
my @all_lines = <FILE>;
foreach $line (@all_lines)
{
$line = lc $line; #convert to lowercase
++$points[$counter] if ($line =~ /$search_word/);
}#end of foreach
close (FILE);
$counter++;
}#end of foreach
}#end of foreach
}#end of search
###################################################################### ####
sub results
{
sumall();
print ("You searched for <b>@string</b><br>");
print ("Total of $sumall results<br>");
while ($sumall != 0)
{
my $max=0;
for ($x=0; $x<($#points+1); $x++)
{
$max=$x if ($points[$x]>$points[$max]);
}
print "$points[$max]: <a href=\"$baseurl$files[$max]\"> $files[$max]</a><br>\n";
$points[$max]=0;
sumall();
}#end of while
# print ("End of results");
}#end of results
###################################################################### ####
sub sumall
{
$sumall=0;
foreach $x (@points)
{
$sumall+=$x;
}
}
###################################################################### ####
sub print_header
{
open (header, "<$headerfile") || return;
while (<header>)
{
print $_;
}
close header;
}
###################################################################### ####
sub print_footer
{
open (header, "<$footerfile") || return;
while (<header>)
{
print $_;
}
close header;
}
###################################################################### ####
а зто dirscan.pl
#!/usr/local/bin/perl
#This is your main file directory on Unix machine
$basedir="/data1/virtualave.net/username/public_html";
#This is the URL of your site, to which the references will be appended
$baseurl="http://home.infocity.de/almen/AFW/index.htm";
#This is the location of the text file with the list of files to search
$fileinfo="$basedir/search/fileinfo.txt";
open (list, ">$fileinfo");
print<<html
Content-type: text/html\n\n
<!--#echo banner=""-->
html
;
work ("$basedir");
exclude();
print ("<br>Printed to: <b>$fileinfo</b><br>");
close (list);
sub work
{
my $dirname = shift;
print "<hr><b>dirname<b>-$dirname: <br>";
opendir (DIR, $dirname);
my @entries = readdir (DIR);
closedir (DIR);
foreach $entry (@entries)
{
next if $entry eq ".";
next if $entry eq "..";
work ("$dirname/$entry") if -d ("$dirname/$entry");
my $temp_name = "$dirname/$entry";
$temp_name =~ s/$basedir//;
print list ("$temp_name\n") if ((-f ("$dirname/$entry")) && ("$dirname/$entry" =~ /\.htm/));
}
}
sub exclude
{
open (list, "<$fileinfo");
my @names=<list>;
close list;
open (output, ">$fileinfo");
foreach $name (@names)
{
#The exclusion list. Any directory you want to exclude
#should be added here as follows: next if $name =~ /\/dir_name/;
#Below are the examples that are applicable to Moskalyuk.com Web site
next if $name =~ /\/private/;
print output ("$name");
print ("$name<br>");
}
close output;
}
но к сожалению не хватает знаний, чтобы их установить и протестировать. В инете всё хорошо расписано, но нет ответов на практические вопросы для новичков:
1.После распаковки файлов я указал URL моего сайта.
- Могу ли я указать вместо URL директорию папки, где находятся файлы сайта на компе для локального тестирования?
- что я должен задать здесь
$basedir="/data1/virtualave.net/username/public_html";?
- Есть ли в скриптах ещё строки, которые надо менять под мою страничку?
2.Каким образом включить зти файлы в сайт?
A. вариант тестирование локально на моём компе
B. вариант загрузка CGI протокола на сервер через windows commander
Оба варианта для меня не ясны. Особенно CGI- протокол.
-Как установить права на запуск файла find.pl в windows commander при соединении по FTP?
-Как вставить find.pl и dirscan.pl в каталог cgi-bin? (в корневую директорию, где лежит папка страницы и index.htm или я должен запросить у админа сервера право на использование CGI и сам протокол?)
3.Как связать форму поиска с результатами поиска? Так?
<FORM action=../../index.htm/cgi-bin/find.pl method=post target="_blank">
<input name="text" type="text" class="suchen" size="20">
<input class="go"name="submit" type="submit" value="Suchen"></FORM>
После внесения юзером одного или нескольких слов и нажатия на button «поиск» должна появиться новая подстраничка с результатми поиска и линками.
Надо ли её строить в HTML коде? Или зто делает скрипт find.pl ?
|