Inside the HTX Template

All the work of formatting the information that is to be returned to the browser is done in the HTX template. Like Active Server Pages, it uses the <%...%> tags to delineate code or values. However, we don't have to include an equals sign, as we do in ASP, when placing the value of a variable in the page. The two special tags <%BeginDetail%> and <%EndDetail%> denote a section that is repeated for each 'record' returned by the Index Server engine. We also have options for displaying the information as separate pages, rather than a single long page. The IDQ variable CiMaxRecordsPerPage tells Index Server how many records to retrieve each time.

Index Server HTX templates also support <%If condition%>...<%Else%>...<%EndIf%>, and in a template we can retrieve the value of any of the controls on the form which originally referenced the IDQ script, or which are listed in the CiColumns line of the script. We can also use the regular HTTP variables, such as SCRIPT_NAME or SERVER_NAME, as we did with ASP in earlier chapters.

IDQ Return Variables Summary

After running the IDQ script, Index Server sets the values of various built-in variables, which indicate the results of the query:

Variable Meaning
CiMatchedRecordCount Total number of documents which match the query.
CiTotalNumberPages Total number of pages used to contain query results.
CiCurrentRecordNumber Number of current document in the total matched.
CiCurrentPageNumber Current page number of query results.
CiFirstRecordNumber Number of the first document on the current page.
CiLastRecordNumber Number of the last document on the current page. May not be correct until after the <%EndDetail%> section.
CiContainsFirstRecord Set to 1 if the current page contains the first document in the query results, or 0 otherwise.
CiContainsLastRecord Set to 1 if the current page contains the last document in the query results, or 0 otherwise. May not be correct until after the <%EndDetail%> section.
CiBookmark Reference to the first document on the current page.
CiOutOfDate Set to 1 if the content index out of date, or 0 if OK.
CiQueryIncomplete Set to 1 if the query could not be completed using the current content index, or 0 if completed.
CiQueryTimedOut Set to 1 if the query exceeded the time limit for query execution, or 0 if completed.
CiRecordsNextPage Number of records on the next page for a paged query.

Here's the 'working parts' of the template file we used to create the query results pages you saw earlier. We've omitted the code that just creates the header and footer:

...
<B>Results of your search for "<%CiRestriction%>".</B><P>
There are <%CiMatchedRecordCount%> documents which match the criteria.
<HR>
<%If CiMatchedRecordCount NE 0%>
  Documents <%CiFirstRecordNumber%> to <%CiLastRecordNumber%><P>
<%EndIf%>
<TABLE WIDTH=100%>
  <%BeginDetail%>
    <TR>
     <%If DocTitle ISEMPTY%>
      <TD>Untitled document</TD>
     <%Else%>
      <TD>Title: <I><B><%DocTitle%></B></I></TD>
     <%EndIf%> 
     <TD COLSPAN="2">Number of criteria hits: <%HitCount%></TD>
    </TR>
    <TR>
     <TD>Filename:<A HREF="<%EscapeURL vpath%>"><%filename%></A>
     </TD> 
     <TD>Size: <%size%> bytes</TD>
     <TD>Updated: <%write%> GMT</TD>
    </TR>
    <TR>
     <TD COLSPAN="3"><I><%characterization%></I></TD>
    </TR>
    <TR>
     <TD COLSPAN="3" ALIGN="CENTER">
      <!-- following must be all on one line -->   
      <A HREF="http://<%SERVER_NAME%>/scripts/srchadm/webhits.exe
           <%EscapeURL vpath%>?CiRestriction=
           <%EscapeURL CiRestriction%>&CiBold=YES">
      Click to highlight the criteria hits in the document.</A> 
     </TD>
    </TR>
    <TR>
     <TD COLSPAN="3" ALIGN="RIGHT">.</TD>
    </TR>
   <%EndDetail%>
</TABLE>
<FORM ACTION="<%EscapeURL SCRIPT_NAME%>?" METHOD="POST">
  <%If CiMatchedRecordCount EQ 0%>
   Enter the criteria for a new search:<P> 
   <INPUT TYPE="TEXT" SIZE="70" MAXLENGTH="70"  
          NAME="CiRestriction">
   <INPUT TYPE="SUBMIT" VALUE="New Search">
   <INPUT TYPE="RESET" VALUE="Clear">
  <%Else%>
   <%If CiRecordsNextPage EQ 0%>
    <HR><B>No more matches.</B> 
    Edit the criteria for a new search:<P> 
    <INPUT TYPE="TEXT" SIZE="70" MAXLENGTH="70" 
           NAME="CiRestriction" VALUE="<%CiRestriction%>">
    <INPUT TYPE="SUBMIT" VALUE="New Search">
   <%Else%>
    <INPUT TYPE="HIDDEN" NAME="CiBookmark" 
           VALUE="<%CiBookmark%>">
    <INPUT TYPE="HIDDEN" NAME="CiBookmarkSkipCount" 
            VALUE="<%CiMaxRecordsPerPage%>">
    <INPUT TYPE="HIDDEN" NAME="CiMaxRecordsPerPage" 
           VALUE="<%CiMaxRecordsPerPage%>">
    <INPUT TYPE="HIDDEN" NAME="CiRestriction" 
           VALUE="<%CiRestriction%>">
    <INPUT TYPE="HIDDEN" NAME="CiScope" VALUE="<%CiScope%>">
    <INPUT TYPE="SUBMIT" 
           VALUE="Next <%CiRecordsNextPage%> Documents">
   <%EndIf%>
  <%EndIf%>
</FORM>
...

From your knowledge of Active Server Pages, it should be obvious how the IDQ variables (such as <%CiRestriction%>) and the values obtained from the search (such as <%DocTitle%>) are used. We create a table to hold the results and, within the <%BeginDetail%> <%EndDetail%> section, create a table row containing the document title, size, last update time, filename, hit count and abstract. Because some documents do not have a title, we use an <%If...%> <%Else%> <%EndIf%> construct to display 'Untitled document' in this case:

  ...
  <%If DocTitle ISEMPTY%>
    <TD>Untitled document</TD>
  <%Else%>
    <TD>Title: <I><B><%DocTitle%></B></I></TD>
  <%EndIf%> 
  ...

Note that we can't put a <%BeginDetail%> <%EndDetail%> section inside an <%If...%> <%Else%> <%EndIf%> construct. If we do, we get an error message saying that an <%Else%> or <%EndIf%> can't be found.

© 1998 by Wrox Press. All rights reserved.