Perlwannabe
Technical User
Hi everyone,
I'm not a Perl programmer at all.
I have an elementary script to create a little search engine,and I would create a filter in order to prevent that certain terms are considered suitable for the search.This in order to avoid to get search results for common short words such as "any" "and" "for" and so on.
The script provides a length filter that cuts off all typed words shorter than a certain length,but it can't work at all as there are,in my case,short terms that,instead are suitable for the search,such as "kit" or "cap" and so on...So I must give up this idea.
Alternatively,I could store these "stop words" in an external list and create a proper expression to handle them,so that they will be simply ignored for the search,but I have no idea about how to do.
I noticed that the script provides a smut filter that works with an exclusion list,censoring all the records containing smut words;I think this could work also for the "stop words",but I should modify the code in order to obtain that my "stop words" are simply ignored for the search,with no censor.
Could anyone please help me to edit properly this code?
Here is the smut filter:
Here is the search routine:
If you need I also could post the whole script
Thanks in advance
Any help will be very appreciated
Sincerely
I'm not a Perl programmer at all.
I have an elementary script to create a little search engine,and I would create a filter in order to prevent that certain terms are considered suitable for the search.This in order to avoid to get search results for common short words such as "any" "and" "for" and so on.
The script provides a length filter that cuts off all typed words shorter than a certain length,but it can't work at all as there are,in my case,short terms that,instead are suitable for the search,such as "kit" or "cap" and so on...So I must give up this idea.
Alternatively,I could store these "stop words" in an external list and create a proper expression to handle them,so that they will be simply ignored for the search,but I have no idea about how to do.
I noticed that the script provides a smut filter that works with an exclusion list,censoring all the records containing smut words;I think this could work also for the "stop words",but I should modify the code in order to obtain that my "stop words" are simply ignored for the search,with no censor.
Could anyone please help me to edit properly this code?
Here is the smut filter:
# Get the smut filter information
unless (open (DATA,"$smutfile")) {die (&error);}
if ($uselock eq '1') {
flock DATA, 2;
seek DATA, 0, 0;
}
@smutinfo = <DATA>;
if ($uselock eq '1') {
flock DATA, 8;
}
close (DATA);
foreach $smutline (@smutinfo){
$smutfilter = $smutfilter.$smutline;
@smutwords = split (/::/,$smutfilter);
}
Here is the search routine:
# Routine for 'words' search
if ($FORM{'mode'} eq "words") {
chomp($FORM{'keywords'});
$searchstring=$FORM{'keywords'};
@words = split (/ /,$searchstring);
foreach $word (@words) {
$wordlength = length($word);
# length filter:
if ($wordlength < $minword) {
$word = split (/ /,$searchstring);
}
}
&heading;
$entries = @input;
if ($position == 0) {
$currentline = $entries;
} else {
$currentline = $position;
}
$found="0";
print "<CENTER><FONT $font SIZE=3><B>Search Results : </B>'$FORM{'keywords'}'<P></FONT></CENTER>";
print "<HR WIDTH=400>";
print "<TABLE WIDTH=500><TR><TD ALIGN=LEFT><FONT $font SIZE=2>";
until ($found > 9 ¦¦ $currentline == 0) {
foreach $word (@words) {
if ($input[$currentline] =~ /$word/i) {
@data = split (/::/,$input[$currentline]);
if ($data[4] ne "") {
# begin smut filter function:
if ($safekey eq "on" && $match == 0) {
foreach $smutword (@smutwords) {
if ($input[$currentline] =~ /$smutword/i) {
$smut = 1;
}
}
unless ($smut == 1) {
print "<A HREF=\"$data[0]\"><B>$data[1]</B></A><BR>";
print "$data[4]<BR>";
print "<I>$data[0]</I><P>";
++$found;
++$match;
}
$smut = 0;
}
if ($safekey eq "off" && $match == 0) {
print "<A HREF=\"$data[0]\"><B>$data[1]</B></A><BR>";
print "$data[4]<BR>";
print "<I>$data[0]</I><P>";
++$found;
++$match;
# end smut filter function
}
}
}
}
--$currentline;
$match = 0;
}
}
If you need I also could post the whole script
Thanks in advance
Any help will be very appreciated
Sincerely