Drag and Drop CGI | 8 | WebReference

Drag and Drop CGI | 8

Advanced ICE Configuration

Search Results Configuration

Customizing the HTML output of the search is a little trickier than customizing the request form. This is because the output is not located in a nice block. Rather, it's embedded within the Perl code and the output is generated in several locations within the code.


Hot Tip

A good way to customize the output of this script is to capture the HTML output from the default script using the Save As function of your browser. Edit this using your HTML editor until the page looks the way you like. Be sure to allow for a variable number of returned links in your layout. Finally, as you work through the remaining paragraphs, you can compare the original HTML from the script with your edited HTML and easily see what changes to make in the Perl code to produce the HTML you want.
The top of the HTML document is generated starting at line 176. The main subroutine, starting at line 166, calls the send_header subroutine with the title of the page. You can modify the title string by changing the line

&send_header("$title: ICE Query Result");

Notice the double quotation marks that tell Perl to insert the value of the $title variable before the send_header subroutine is called to send the top portion of the HTML document to the browser. If you don't want to include the title from the search form, you can remove the $title variable. To specify the title explicitly, you could do this:

&send_header('My Corp Search Results');

Starting at line 211 is the code that responds to an error in the search. Modify the print statements to produce the HTML you need for the body section. If you are using tables to format your page, you might change the original code from

if($err){
    print "Query was: $query<BR>\n";
    print "Problem: $err\n";
    print "</BODY>";
    return undef;
  }

to

if($err){
    print "<TR><TD>Query was:</TD><TD>$query</TD></TR>\n";
    print "<TR><TD>Problem:</TD><TD>$err</TD></TR>\n";
    print "</TABLE></BODY>";
    return undef;
  }

Directly below this section is a series of print statements (lines 217-234) that produce a report of the preferences selected for the query using an HTML <UL> list. You can delete this section if you don't want to print the preferences, or you can change the style by editing the HTML code produced. For example, those of you who like to use those little colored balls for list bullets could do this:

print "Preferences set for this query:\n";
    print "<P>\n";
  if ($query) {
          print "<IMG SRC=\"../images/bluball.gif\"> query was
    \"$query\"\n";
  }
    if($context){
           print "<IMG SRC=\"../images/bluball.gif\"> context was 
set to $context.\n";
...

Notice the backslash \ before the double quotation marks within the line. They tell Perl to ignore the meaning of the special character that follows.

At line 235 is the code that produces the main listing of the returned links:

if($page){
    print "<P>The index contains the following\n";
    print "items relevant to the query\n";
    print "$page\n";
  }else{
    print "<P> Nothing found.\n";
  } 
  print "</BODY>\n";

The if statement will print either the top section (before the word else) if the search found some pages (stored in the $page variable) or the bottom section (print "<P> Nothing found. \n";) if nothing was found. If you change the formatting here, be sure to change both sections. The last line will always be printed, since it is outside the if statement (see Appendix A regarding the if statement). You can add things that should always appear on the page, such as navigation links just before the </BODY> tag is printed.

The final section to configure produces the code for each document matched in the search. The following code is found beginning at line 276:

foreach $w (@tmplist){
    local($freq,$file,$title,@hits)=split(/\n/,$w);
    $hitcount++;
    ###print "$freq,$title\n";
    unless($title) { $title="(NO TITLE)"; } 
    $page .= "<LI> <A HREF=\"$file\"><I>$title</I></A><BR>\n";
    $page .= "$file<BR>\n";
    foreach $line (@hits){
      $page .= "$line<BR>\n";
    }
  }

To modify the HTML produced when the search document has no title, change the $title variable as follows:

unless($title) { $title="(NO TITLE)"; }

Note: This $title variable holds the title of the document matched in the search and is a different $title variable than that used for the page title.

The HTML produced for each matched document is contained in these lines:

$page .= "<LI> <A HREF=\"$file\"><I>$title</I></A><BR>\n";
$page .= "$file<BR>\n";

The $file variable holds the URL (relative to the server root) of the matched document. The $title variable as described previously holds either the <TITLE> of the HTML document or the (NO TITLE) string. The second line just prints the URL of the file below the hyperlinked title. You can delete this line if you don't want your filenames hanging out there for people to see. Displaying the actual URL of the file is useful, however, when the results page is printed.

Once you've finished your modifications, save the script and upload it to your ISP or SA's server. We generally use a different name for scripts that contain major changes (e.g., ice-form2.cgi, ice-form3.cgi, and so on). If you do this, be sure to modify the search form to call the new script. Once the script is on the server, change the file permissions in the usual way with your FTP or Telnet client, and test it by entering the script name from the command line:

./ice-form2.cgi

If you made any mistakes modifying the code, you will see detailed error messages at this point. The most common will be missing quotation marks in strings or a missing backslash \ for a Perl special character within a double-quoted string. Once the script is happy running from the command line, it should work from the Web browser. If you changed the form script name (i.e., ice-form2.cgi), remember to change the ACTION= parameter on your custom search form. The script will use the new name automatically if you're using the script- generated search form.


Hot Tip

When modifying scripts like this, we usually have the text editor, HTML editor, FTP client, Telnet client, and Web browser all running at the same time. When we change the code, we save the file, send it to the server with the FTP client, and test it with the Web browser or Telnet client. With practice, you'll soon be able to test scripts on the Web server almost as fast as you can save files to your local machine.


Comments are welcome

Copyright © 1997 Addison-Wesley Pub Co. and
Created: Oct. 24, 1997
Revised: Oct. 27, 1997

URL: http://webreference.com/dev/dndcgi/search2.html