bobbyboy has asked for the wisdom of the Perl Monks concerning the following question:
I have a search engine which is working fine but I want to add a couple of features to it such as a title to a search which has found a match. A heading something like here are your Search Results. I would also like to number the results and keep the number of matches to 10 on a page.
I would be very grateful if some one could help me!!!
Here is the code
#!/usr/bin/perl require "get_form_data.pl"; &get_form_data(); $search_term = $FORM{'search'}; my @match; opendir(DIR, "."); while($file = readdir(DIR)) { next if($file !~ /.html/); open(FILE, $file); $found_match = 0; $title = ""; while(<FILE>) { if(/$search_term/i) { $found_match = 1; } if((/<TITLE>/) || ($found_title)) { if((/<\/TITLE>/) && (/<TITLE>/)) { chop; $title = $_; $title =~ s/<TITLE>//g; $title =~ s/<\/TITLE>//g; } else { if($found_title == 1) { $title = $_; $found_title = 2 } elsif($found_title == 2) { $found_title = 0; } else { $found_title = 1; } } } } if($found_match) { push @match, qq ( <HTML>\n<BODY BGCOLOR=\"#000099\"link=\"#FFFF00\">\n <font face=\"Verdana\"><A HREF="$file">$title</A></font><p>\n ); } close(FILE); } closedir(DIR); # now output print "Content-type: text/html\n\n"; if (@match) { for (@match) { print; } } else { print "<HTML>\n<BODY BGCOLOR=\"#000099\"TEXT=\"#FFFFFF\">\n"; print "<H3>\n"; print "<font face=\"Verdana\">Sorry!!!</font>\n"; print "</H3>\n"; print "<font face=\"Verdana\">Sorry, we were unable to match your qu +ery<p>Please use the <STRONG>FEEDBACK</STRONG> button</font>\n"; print "<font face=\"Verdana\">to go to the form and let us know what + you are looking for.</font>\n\n"; } exit;
2001-04-05 Edit by Corion: Added formatting and CODE tags, changed title
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Search engine result limiting (was: help!!)
by arturo (Vicar) on Apr 05, 2001 at 17:06 UTC | |
|
Re: Search engine result limiting (was: help!!)
by Hero Zzyzzx (Curate) on Apr 05, 2001 at 17:01 UTC | |
|
Re: Search engine result limiting (was: help!!)
by merlyn (Sage) on Apr 05, 2001 at 16:53 UTC | |
|
Re: help!!
by djw (Vicar) on Apr 05, 2001 at 16:43 UTC |