How to write search result templates

mnoGoSearch users have an ability to customize search results (output of search.cgi or search.php). You may do it by providing template file search.htm, which should be located in /etc/ directory of mnoGoSearch installation.

Template file is usual HTML file, which is divided into sections. Keep in mind that you can just open template file in your favorite browser and get the idea of how the search results will look like.

Each section begins with <!--sectionname--> and ends with <!--/sectionname--> delimiters, which should reside on a separate line.

Each section consists of HTML formatted text with special meta symbols. Every meta symbol is replaced by it's corresponding string. You can think of meta symbols as of variables, which will have their appropriate values while displaying search results.

Format of variables is the following:


$(x) - plain value
$&(x) - HTML-escaped value and search words highlighted.
$%(x) - value escaped to be used in URLs
$^(x) - search words highlighted.

Template sections

The following section names are defined:

TOP - This section is included first on every page. You should begin this section with <HTML><HEAD> and so on. Also, this is a definitive place to provide a search form. There are two special meta symbols you may use in this section:


$(self)  - argument for FORM ACTION tag
$(q)     - a search query
$(ndocs)  - total number of documents in the database
$(cat)    - current category value
$(tag)      - current tag value
$(rN) - random number (here N is a number)

If you want to include some random banners on your pages, please use $rN. You should also place string like "RN xxxx" in 'variables' section (see below), which will give you a range 0..xxxx for $rN. You can use as many up random numbers as you want.

Example: $(r0), $(r1), $(r45) etc.

Simple top section should be like this:


<!--top-->
<HTML>
<HEAD>
 <TITLE>mnoGoSearch: $(q)</TITLE>
</HEAD>
<BODY>

<FORM METHOD=GET ACTION="$(self)">
 <INPUT TYPE="hidden" NAME="ul" VALUE="">
 <INPUT TYPE="hidden" NAME="ps" VALUE="20">
 Search for: <INPUT TYPE="text" NAME="q" SIZE=30 
 VALUE="$&(q)">
 <INPUT TYPE="submit" VALUE="Search!"><BR>
</FORM>
<!--/top-->

There are some variables defined in FORM.

lang limit results by language. Value is a two-letter language code.


<SELECT NAME="lang">
<OPTION VALUE="en" SELECTED="$(lang)">English
.....
</SELECT>
    

ul is the filter for URL. It allows you to limit results to particular site or section etc. For example, you can put the following in the form

Search through:


<SELECT NAME="ul">
<OPTION VALUE=""            SELECTED="$(ul)">Entire site
<OPTION VALUE="/manual/"    SELECTED="$(ul)">Manual
<OPTION VALUE="/products/"  SELECTED="$(ul)">Products
<OPTION VALUE="/support/"   SELECTED="$(ul)">Support
</SELECT>

to limit your search to particular section.

The expression SELECTED="$(ul)" in example above (and all the examples below) allows the selected option to be reproduced on next pages. If search front-end finds that expression it prints the string SELECTED only in the case OPTION VALUE given is equal to that variable.

ps is default page size (e.g. how many documents to display per page).

q is the query itself.

pn is ps*np. This variable is not used by mnoGoSearch, but may be useful for example in <!INCLUDE CONTENT="..."> directive if you want to include result produced by another search engine.

Following variables are concerning advanced search capabilities:

BOTTOM This section is always included last in every page. So you should provide all closing tags which have their counterparts in top section. Although it is not obligatory to place this section at the end of template file, but doing so will help you to view your template as an ordinary html file in a browser to get the idea how it's look like.

Below is an example of bottom section:


<!--bottom-->
<P>
<HR>
<DIV ALIGN=right>
<A HREF="http://search.mnogo.ru/">
<IMG SRC="mnogosearch.gif" BORDER=0 
ALT="[Powered by mnoGoSearch search engine software]">
</A>
</BODY>
</HTML>
<!--/bottom-->

RESTOP This section is included just before the search results. It's a good idea to provide some common search results. You can do so by using the next meta symbols:

Below is an example of 'restop' section:


<!--restop-->
<TABLE BORDER=0 WIDTH=100%>
<TR>
<TD>Search<BR>results:</TD>
<TD><small>$(WE)</small></TD>
<TD><small>$(W)</small></TD>
</TR>
</TABLE>
<HR>
<CENTER>
Displaying documents $(first)-$(last) of total <B>$(total)</B> found.
</CENTER>
<!--/restop-->

RES - This section is used for displaying various information about every found document. The following meta symbols are used:

Note: It is possible to specify maximum number of characters returned by any of the above variables. E.g. $DU may return a long URL that may break page table structure. To specify maximum number of characters in the displayed URL's, use $(DU:xx), where xx - maximum number of characters:

$(DU:40)

will return a URL, and if it is longer than 40 character, only 40 characters will be displayed including the ending points:

http://very.long.url/path/veery/long/...

Here is an example of res section:


<!--res-->
<DL><DT>
<b>$(DN).</b><a href="$(DU)" TARGET="_blank">
<b>$(DT)</b></a> [<b>$(DR)</b>]<DD>
$(DX)...<BR>
<b>URL: </b>
<A HREF="$(DU)" TARGET="_blank">$(DU)</A>($(DC))<BR>
$(DM), $(DS) bytes<BR>
<b>Description: </b>$(DD)<br>
<b>Keywords: </b>$(DK)<br>
</DL>
<UL>
$(CL)
</UL>
<!--/res-->

CLONE - The contents of this section is included in result just instead of $CL meta symbol for every document clone found. This is used to provide all URLs with the same contents (like mirrors etc.). You can use the same $(D*) meta symbols here as in 'res' section. Of course, some information about clone, like $(DS), $(DR), $(DX) will be the same so it is of little use to place it here.

Below is an example of 'clone' section.


<!--clone-->
<li><A HREF="$DU" TARGET="_blank">$(DU)</A> ($(DC)) $DM
<!--/clone-->

RESBOT - This is included just after last 'res' section. You usually give a navigation bar here to allow user go to next/previous results page.

Navigator is a complex thing and therefore is constructed from the following template sections: navleft, navleft_nop

These are used for printing the link to the previous page. If that page exists, <!--navleft--> is used, and on the first page there is no previous page, so <!--navleft_nop--> is used.


<!--navleft-->
<TD><A HREF="$(NH)"><IMG...></A><BR>
<A HREF="$(NH)">Prev</A></TD>
<!--/navleft-->

<!--navleft_nop-->
<TD><IMG...><BR>
<FONT COLOR=gray>Prev</FONT></TD>
<!--/navleft_nop-->

navbar0 - This is used for printing the current page in the page list.


<!--navbar0-->
<TD><IMG...><BR>$(NN)</TD>
<!--navbar0-->

navright, navright_nop - These are used for printing the link to the next page. If that page exists, <!--navright--> is used, and on the last page <!--navright_nop--> is used instead.


<!--navright-->
<TD>
<A HREF="$(NH)"><IMG...></A>
<BR>
<A HREF="$(NH)">Next</A></TD>
<!--/navright-->

<!--navright_nop-->
<TD>
<IMG...>
<BR>
<FONT COLOR=gray>Next</FONT></TD>
<!--/navright_nop-->

navbar1 - This is used for printing the links to the other pages in the page list.


<!--navbar1-->
<TD>
<A HREF="$(HR)">
<IMG...></A><BR>
<A HREF="$(NH)">$(NN)</A>
</TD>
<!--/navbar1-->

This is an example of 'resbot' section:


<!--resbot-->
<HR>
<CENTER>
Result pages: $(NL)$(NB)$(NR)
</CENTER>
<!--/resbot-->

notfound - As its name implies, this section is displayed in case when no documents are found. You usually give a little message saying that and maybe some hints how to make search less restrictive.

Below is an example of notfound section:


<!--notfound-->
<CENTER>
Sorry, but search hasn't returned results.<P>
<I>Try to compose less restrictive search query or check spelling.</I>
</CENTER>
<HR>
<!--/notfound-->

noquery - This section is displayed in case when user gives an empty query. Below is an example of noquery section:


<!--noquery-->
<CENTER>
You haven't typed any word(s) to search for.
</CENTER>
<HR>
<!--/noquery-->

error - This section is displayed in case some internal error occurred while searching. For example, database server is not running or so. You may provide the following meta symbol:$(E) - error text.

Example of error section:


<!--error-->
<CENTER>
<FONT COLOR="#FF0000">An error occured!</FONT>
<P>
<B>$(E)</B>
</CENTER>
<!--/error-->

Variables section

There is also a special variables section, in which you can set up some values for search.

Special variables section usually looks like this:


<!--variables
DBAddr		mysql://foo:bar@localhost/search/
DBMode		single
VarDir          /usr/local/mnogosearch/var/
LocalCharset	iso-8859-1
BrowserCharset  iso-8859-1
TrackQuery	no
Cache		no
DetectClones	yes
HlBeg		<font color="blue"><b><i>
HlEnd		</i></b>
R1		100
R2		256
Synonym		synonym/english.syn
-->

Note: Database option DBAddr works only for SQL back-end and does not matter for built-in text files support. Like in indexer.conf, host part in DBAddr argument takes affect for natively supported databases only and does not matter for ODBC databases. In case of ODBC use database name part of DBAddr to specify ODBC DSN.

VarDir command specifies a custom path to directory that indexer stores data to when use with use with built-in database and in cache mode. By default /var directory of mnoGoSearch installation is used.

LocalCharset specifies a charset of database. It must be the same with indexer.conf LocalChatser.

BrowserCharset specifies which charset will be used to display results. It may differ from LocalCharset. All template variables which correspond data from search result (such as document title, description, text) will be converted from LocalCharset to BrowserCharset. Contents of template itself is not converted, it must be in BrowserCharset.

Use "Cache yes/no" to enable/disable search results cache.

Use "Clone yes/no" to enable/disable closes detection.

HlBeg and HlEnd commands are used to configure search results highlighting. Found words will be surrounded in those tags.

There is an Alias command in search.htm, that is similar to the one in indexer.conf, but it affects only search results while having no effect on indexing. See Aliases section for details.

R1 and R2 specify ranges for random variables $(R1) and $(R2).

Synonym command is used to load specified synonyms list. Synonyms file name is either absolute or relative to /etc directory of mnoGoSearch installation.

Includes in templates

You may use <!INCLUDE Content="http://hostname/path"> to include external URLs into search results.

WARNING: You can use <!INCLUDE> ONLY in the following template sections:


<!--top-->
<!--bottom-->
<!--restop-->
<!--resbot-->
<!--notfound-->
<!--error-->

This is an example of includes usage:


<!--top-->
....
<!INCLUDE CONTENT="http://hostname/banner?query=$&(q)">
...
<!--/top-->

Using several formats with one template

mnoGoSearch allows to define several (up to 100) descriptions for the same template section. It is often reasonable, for example, to have both "Long" and "Short" search results format. To implement this just write two separate "res" template sections for "Long" and "Short" result output formats one by one. The sample of different formats usage is given in search.htm-dist. Note that "res" is not the only section - every template section may be given several times. So, it is easy for example to prepare multi-language templates.

Security issues

WARNING: Since the template file contains such info as password, it is highly recommended to give the file proper permissions to protect it from reading by anyone but you and search program. Otherwise your passwords may leak.