Compass Server 3.0 Developer's Guide

[Contents] [Previous] [Next] [Last]

Chapter 4
Pattern Files for UI Templates

Each time the Compass Server End User page is displayed, it is assembled from several components. The content of each component is defined by a pattern file.

This chapter has the following topics related to pattern files:

What is a Pattern File?

A pattern file is an HTML file. It can contain HTML, JavaScript, or any other content that can be displayed by a web browser.

Each pattern file defines a piece of a Compass Server End User page. The piece at the very top of the page has the tags that start an HTML page, such as <HTML>, <HEAD>, and <BODY>. The piece at the bottom of the page has the tags that close an HTML page, such as </BODY> tag and </HTML> tags.

Pattern files can use special variables to access data such as the number of documents that match the current search query, which category was being searched, and so on. You can use these variable directly in HTML and also in JavaScript code. If you want to use these variables inside Java code, you need to use the Java Search SDK, which is described in the Chapter 14, "Using Java to Access and Modify the Compass Server Database."

Using Variables

Each special variable starts with $$, for example, $$RDM-Hits-Searched. See Attributes derived from the Compass Database Schema for a full list of the variables.

You can use the pre-defined variables in three ways:

SOIF Attributes

Some of the variables you can use in the pattern files have their values set by variables in the configuration file. For example, the value of the $$RDM-rotated-color variable is drawn from a list that is defined in the configuration file. Other variables give you information about the current environment, or what the user is doing, for example $$category variable tells you what category the user is currently browsing, while the $$RDM-scope variable tells you what text the user was using as their search criteria.

Yet other variables reveal data that is stored in the Compass Server's database. Each entry in the database is known as a resource description (RD). Each resource description contains data about a resource, such as a web page, on the network. Each resource description has multiple attributes or fields. These attributes are known as SOIF attributes, where SOIF stands for Summary Object Interchange Format.

A SOIF attribute is an attribute whose value is derived from a field in the database. For each SOIF attribute, there is a $$ variable that directly corresponds to that attribute. For example, each resource description has attributes Description and Title, consequently you can use the variables $$description and $$title.

Some of these SOIF attributes are fairly standard, such as description and title. However, developers can set up the schema of their database however they like.

When editing the schema of your database (as discussed in the "Compass Server Administrator's Guide"), you can add new attributes or delete existing attributes. When the robot finds a resource, such as an HTML file, to be indexed, it needs to know how to get the data to assign to each attribute for storage in the database. The most common way to map resource data to database attributes is through the use of the META tag. That is, the robot looks for a META tag whose name is the same as the attribute, and if it finds such a tag, the robot takes the content of the tag and uses it as the value of the attribute in the database.

Anyway, as you can see, the precise list of $$SOIF-attribute variables varies from database to database, depending on the schema of the database.

List of Variables

This section discusses the $$ variables you can use in your pattern files. The variables are presented in tables categorized by use.

The variables listed in the previous table and the next table change for each document or category, and should only be used in pattern files for hit components.

Table 4.2. Hit variables

Variable Name Description
$$category
The category currently being processed.

$$score
The score indicates how well the current category or document matches the search criteria if a search was submitted.

$$RDM-Hit
The number of the hit currently being processed.

$$RDM-Is-First-Hit
This variable has the value true if the current hit is the first hit. If the hit is not the first hit, this variable has no value.

You could use this variable with the special conditional syntax. The following example, draws a horizontal line before the title and description of the first hit:

$$RDM-Is-First-Hit[<HR>]
$$Title $$Description
This example would be used in a document-match-hit or category-match-hit pattern file.

$$subclassification-count
This is the number of subcategories in the category being processed.

$$categorized-count
This is the number of documents in the category being processed.

Table 4.3. Variables for Use in Top Pattern Files only

$$RDM-Hits-Available
The number of available hits (documents or categories in the browsed category or that matched the search criteria)

$$RDM-Hits-Searched
The number of entries in the database that were checked during the search. This is usually the total number of entries in the database.

$$RDM-has-hits
This variable has the value true if the search or browse found categories or documents. For example:

$$RDM-has-hits[<H3>There are some hits</H3>]

The variables listed in the next table can be used in any pattern file.

Table 4.4. Variables that are constant for each browse or search submission

Variable Value

$$UI
Indicates the kind of End User page in use, that is, indicates whether it is a browse or search template. The value will be bw or sr.

$$RDM-View-Template
This is the name of the template in use. For example, if the configuration file for the template is normal.conf, then $$RDM-View-Template has the value normal.

$$Browse-Category
The category that the user is browsing.

$$Search-Category
The category that the user is searching.

$$RDM-Scope
The string that was submitted as the search criteria.

$$taxonomy 
The name of the top level category in the taxonomy tree. For example, if the top level category is netscape, with subcategories software and documentation, which in turn each have their own subcategories, $$taxonomy is netscape.

$$RDM-Version
Version of the Compass Server serving the request.

$$RDM-Server
URL of the server where the Compass Server is installed.

Table 4.5. Page-related variables

$$Page
The current page. If there are more hits than can fit on one page (as determined by $$Chunk-size), multiple pages may be needed to display all the hits. $$Page evaluates to the page number for the page that is currently being viewed.

$$Prev-Page
The previous page. If there are more hits than can fit on one page (as determined by $$Chunk-size), multiple pages may be needed to display all the hits. $$Prev-Page evaluates to the page number for the page previous to the one that is currently being viewed.

$$Next-Page
The next page. If there are more hits than can fit on one page (as determined by $$Chunk-size), multiple pages may be needed to display all the hits. $$Next-Page evaluates to the page number for the page following the one that is currently being viewed.

$$RDM-Hit-Max
The number of the last hit to display in the current page.

$$RDM-Hit-Min
The number of the first hit to display in the current page.

$$RDM-Is-First-Page
This variable has the value true if the current page is the first page that displays a list of hits. If the current page is not the first page, the variable has no value.

You could use this variable with the special conditional syntax, for example:

$$RDM-Is-First-Page[text for the first page only]
$$RDM-Hits-Returned
The number of matching documents displayed in the current page. This is equal to or less than $$Chunk-size, which defines the maximum number of documents displayed in a page.

For example, the last page may show only 5 hits, in which case $$RDM-hits-returned is 5 for the last page, although for all other pages it might be 10, which is the value of $$Chunk-size.

$$RDM-has-hits-more 
This variable has the value true if there are more than one page worth of hits, otherwise it has no value.

$$RDM-has-hits-zero 
This value returns true if there are no hits, otherwise it has no value. For example:

$$RDM-has-hits-zero[<H3>There are NO hits</H3>]

$$RDM-has-hits-this 
This variable has the value true if all the hits fit on one page, otherwise it has no value.

Table 4.6. Developer-editable variables defined in the configuration file

Variable name Value

$$Chunk-size
The number of hits that fit in a page. The maximum allowable value is 2730.

$$RDM-Rotated-Color
A color in the list of RDM-rotated-colors. Each time you access this variable, the value moves on to the next color in the list. See Determining What Colors to Use for Documents and Categories for details. This variable can only be used in pattern files for hit components (category-browse-hit, category-match-hit, document-browse-hit, document-match-hit.)

$$RDM-Score-Icon
This variable evaluates to a URL for an image that represents the ranking of a hit. This image will show one, two, three, four, or five stars (or something like stars) that indicates how well a document matched a search query. For example:

"http/your.server.com/images/star1.gif"
$$RDM-Score-Image
This variable evaluates to an <IMG> tag that points to the URL for an image that represents the ranking of a hit. For example:

<IMG SRC="http/your.server.com/images/star1.gif">

Pattern File Summary

This section briefly discusses what the pattern files for each component should or could do. Although you can define pattern files to do whatever you want, there are some basic guidelines that cover typical uses of pattern files.

browse-mode-top and search-results-mode-top

The pattern files for the browse-mode-top and search-results-mode-top components define the content at the top of browse-mode pages or search-mode pages as appropriate. This section refers to these pattern files collectively as top pattern files.

Since top pattern files start a page, they must include the <BODY> tag for the whole page. You can set background color, link color, text color and so on for the whole page by specifying appropriate attributes for the <BODY> tag. For a list of all the attributes for the <BODY> tag see the entry for BODY in the HTML Tag Reference.

The top pattern files should also define the title for the Compass End User Page (that is, they should have a <TITLE> tag.) These files should also include any desired META tags or other tags that need to go between <HEAD> and </HEAD>.

Top pattern files often contain a text field for search criteria. If you want both browse-mode and search-results mode pages to show the text field, then you must include the text field in the pattern files for both the browse-mode-top and search-mode-top components. (For information about defining forms that have text entry field for search criteria, see Using Forms to Submit Searches.)

If you want the Compass Server End User page to display a logo for your company, instead of, or as well as, the Compass Server logo, you need to put the logo in the top pattern files.

category-browse-top and category-search-results-top

The pattern file for the category-browse-top component defines the introduction to the list of categories in the browsed category. The pattern file for the category-search-results-top component defines the introduction to the list of categories that match the search criteria when a search was submitted. These files are known collectively in this section as category-top files.

If you want the subcategories or matching categories to be displayed in a structure such as a table or list, you can define the opening tag, such as <TABLE> or <UL> in the category-top files.

Table 4.3. Variables for Use in Top Pattern Files only lists some variables that may be useful in category-top pattern files. The page-related variables, as discussed in Table 4.5 may also be useful in category-top files. Additionally, the following variables may be useful:

$$Browse-Category
The category that the user is browsing.

$$Search-Category
The category that the user is searching.

$$RDM-Scope
The string that was submitted as the search criteria.

$$subclassification-count
This is the number of subcategories in the category being processed.

$$categorized-count
This is the number of documents in the category being processed.

category-browse-hit and category-search-results-hit

The pattern file for the category-browse-hit component is invoked for each sub-category in the browsed category. The pattern file for the category-search-results-hit component is invoked for each category that matches the search criteria when a search was submitted. This section refers to these pattern files collectively as category-hit files.

You can define category-hit files to display the information about the category being processed. If the corresponding category-top file started a list, then you should display each category as a list item. If the corresponding category-top file started a table, then you should display each category as a table row. You can, if desired, set the background of each row to $$RDM-rotated-color so that the table uses alternating colors for the rows. For more details, see Determining What Colors to Use for Documents and Categories.

Variables that may be useful in category-hit files include:

$$id
The id of the category being processed, which is usually the name of the category. (This is derived from the Compass Server database.)

If this variable is used, it used must be listed in the appropriate RDM-attribute-view variable in the configuration file, as discussed in Specifying Which Attributes Can Be Viewed in Hit Components.

$$browse-category
The category that the user is browsing.

$$search-category
The category in which the user is searching.

$$category
The category currently being processed.

$$subclassification-count
This is the number of subcategories in the category being processed.

$$categorized-count
This is the number of documents in the category being processed.

category-browse-bottom and category-search-results-bottom

The pattern file for the category-browse-bottom component defines the content that follows the list of subcategories in a browse-mode page. The pattern file for the category-search-results-bottom component defines the content that follows the list of categories that matched the search criteria when a search was submitted. This section refers to these two files collectively as category-bottom files.

If a category-top file start a structure such as a table or list, the corresponding category-bottom file must close that structure, for example by writing a </TABLE> or </UL> tag.

document-browse-top and document-search-results-top

The pattern file for a document-browse-top component defines the introduction to the list of documents in a browsed category. The pattern file for a document-search-results-top component defines the introduction to the list of documents returned by a search submission. These two pattern files are referred to collectively in this section as document-top files.

If you want to display the documents in a structure such as a table or a list, you can define the opening tag, for example <TABLE> or <OL> in the document-top files.

Table 4.3. Variables for Use in Top Pattern Files only lists some variables that can be useful in document-top pattern files. The page-related variables, as discussed in Table 4.5, can also be useful in document-top files. Additionally, the following variables may be useful:

$$Browse-Category
The category that the user is browsing.

$$Search-Category
The category that the user is searching.

$$RDM-Scope
The string that was submitted as the search criteria.

document-browse-hit and document-search-results-hit

The pattern file for the document-browse-hit component is executed once for each document in the browsed category. The pattern file for the document-search-hit component is executed once for each document that matches the search criteria when a search has been submitted. These pattern files are referred to collectively in this section as document-hit files.

Usually document-hit files write the data about the document currently being processed.

You can define the document-hit files to display the documents however you like. However, it is common practice to display them in a table, with each document displayed in its own row, where each row has one cell that shows the ranking icon (if applicable) and one cell that shows the document description. You can, if desired, set the background of each row to $$RDM-rotated-color so that the table uses alternating colors for the rows. For more details, see Determining What Colors to Use for Documents and Categories.

To retrieve information about a document, you can use the SOIF variables, as discussed in Table 4.1. Attributes derived from the Compass Database Schema.

Other variables that may be useful in document-hit files include:

$$RDM-Hit
The number of the hit currently being processed.

$$RDM-Is-First-Hit
This variable has the value true if the current hit is the first hit. If the hit is not the first hit, this variable has no value.

You could use this variable with the special conditional syntax. The following example, draws a horizontal line before the title and description of the first hit:

$$RDM-Is-First-Hit[<HR>]
$$Title $$Description
This example would be used in a document-match-hit or category-match-hit pattern file.

$$RDM-Rotated-Color
A color in the list of RDM-rotated-colors. Each time you access this variable, the value moves on to the next color in the list. See Determining What Colors to Use for Documents and Categories for details. This variable can only be used in pattern files for hit components (category-browse-hit, category-match-hit, document-browse-hit, document-match-hit.)

$$score
The score indicates how well the current category or document matches the search criteria if a search was submitted.

$$RDM-Score-Icon
This variable evaluates to a URL for an image that represents the ranking of a hit. This image will show one, two, three, four, or five stars (or something like stars) that indicates how well a document matched a search query. For example:

"http/your.server.com/images/star1.gif"
$$RDM-Score-Image
This variable evaluates to an <IMG> tag that points to the URL for an image that represents the ranking of a hit. For example:

<IMG SRC="http/your.server.com/images/star1.gif">

document-browse-bottom and document-search-results-bottom

The pattern file for the document-browse-bottom component writes concluding remarks at the bottom of the list of documents in a browsed category. The pattern file for the document-search-results-bottom component writes the concluding remarks at the bottom of the list of documents returned by a search submission. These files are known collectively as document-bottom files in this section.

Often these files do nothing, or they write closing tags such as </TABLE> or </OL> that were opened in the corresponding document-top components. If the document-top files open structures such as tables or lists, you must close these structures in the corresponding document-bottom files.

browse-bottom and search-results-bottom

The pattern files for the browse-bottom and search-results-bottom components define the content that appears at the bottom of browse-mode and search-results mode pages as appropriate.

Since these files end the page, they should include </BODY> and </HTML> tags.


[Contents] [Previous] [Next] [Last]

Last Updated: 02/07/98 20:49:01

Any sample code included above is provided for your use on an "AS IS" basis, under the Netscape License Agreement - Terms of Use