Handle Search



  sub HandleSearch  {
	local($m, $n, @rec);
	$pat = $CookedInput{search};
	# slow DollarAmpersand removed
	$pat =~ s/([+?.*()[\]{}|\\])/\\$1/g;
	$results = Results;
	$results = "for $1" if $pat =~ /\W+/;
	print "<head><title>Search $results</title></head>\n";
	print "<body><h1>$LogoImage Search Results</h1>\n";
	while (($key, $value) = each %db){
	$n++;
	%rec = split($FieldSeparator, $value);
	if ($key =~/\b(\w*($pat)\w*)\b/i ||
	$rec{text} =~ /\b(\w*($pat)\w*)\b/i){
		$m++;
		# More DollarAmpersand s removed
		print "<a href=\"$ScriptUrl\?$key\">$key<\/a> . . . . . .  $1<br>\n";
	}
	}
	$m = $m || No;
	print "<hr>$m pages found out of $n pages searched.</body>";
  }

- Two questions:

1. What does this line do?

$pat =~ s/([+?.*()[\]{}|\\])/\\$1/g;

A: It precedes special punctuation characters with a backslash.

1. What is "Results," here? A constant? An unquoted literal?

$results = Results;


ChrisGarrod removed the period for that line, and was impressed by the result obtained. The query search=. returns every page. The output line below produces a borderless table with the PageName right justified and any context found left justified. You have to add <table> near the end of the previous print statement, and </table> at the beginning of the last one.

Compare the result: http://igpp.ucsd.edu/cgi ... i?search=.broken

 print "<tr><td align=right><a href=\"$ScriptUrl\?$key\">$key<\/a> <td align=left>$1<br>\n";

PleaseComment or AnswerMe: how can I make the $1 above TurnBlue the things that match the LinkPattern? AsAnchor seems to only work on single clumps of characters, not sentences.

 

Last edited January 17, 2002
Return to WelcomeVisitors