Using search result templates
=============================
General templates information
-----------------------------
Since version 2.1 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 favourite browser and
get the idea of how the search results will look like.
Each section begins with and ends with
delimiters, which should reside on a separate line.
Each section consists of HTML formatted text with special meta symbols. Meta
symbol is one- or two-letter name with the preceding $ sign (examples: $DX,
$V). 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.
Template sections
-----------------
The following section names are defined:
top This section is included first on every page. You should begin this
section with
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:
$A - argument for FORM ACTION tag
$Q - your query, escaped to be printed in HTML form.
$q - your query, escaped to be printed in URLs. You may
use it for links to find the same query in other search engines:
Find "$Q" in AltaVista
$ndocs - total number of documents in the database
$cat - current category value
$cat(0) - the same as $cat
$cat(1) - category on one level above
$cat(X) - category on X levels above
$g - current tag value
$g(0) - the same as $g
$g(X) - tag without X trailing characters
$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 up to MAXRANDOM numbers as N (defined in search.h, default is
128). Example: $r0, $r1, $r45 etc.
Simple top section should be like this:
mnoGoSearch: $Q
There are some variables defined in FORM.
'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:
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 frontend finds that expression it prints the string SELECTED
only in the case OPTION VALUE given is equal to that variable.
[OK, I see this description is confusing, anyway - if you want your
selection to be "saved", use this format. --kir.]
'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 $iurl directive if you want to include result
produced by another search engine.
Next variables are concerning advanced search capabilities.
'm' can be used to choose default search type if your query consists of
more than one word. In case m=any, the search will try to find at least
one word, in case m=all, the search is more restrictive - all words
should be in the document. If m=bool query string is considered as
a boolean expression.
'o' is used to specify the output format, so user can select different
formats, such as long, short etc.
[FIXME: how it is done? Alex please write this section]
'dt' is time limiting type. There are three types supported.
If 'dt' is 'back', that means you want to limit result to recent pages,
and you should specify this "recentness" in variable 'dp' in the form
'xxxA[yyyB[zzzC]]'. Spaces are allowed between xxx and A and yyy and
so on). xxx, yyy, zzz are numbers (can be negative!) A, B, C can be
one of the following (the letters are the same as in strptime/strftime
functions):
s - second
M - minute
h - hour
d - day
m - month
y - year
Examples:
4h30m - 2 hours and 30 minutes
1Y6M-15d - 1 year and six month minus 15 days
1h-60m+1s - 1 hour minus 60 minutes plus 1 second
If 'dt' is 'er' (which is short for newer/older), that means the search
will be limited to pages newer or older than date given. Variable dx
is newer/older flag (1 means "newer" or "after", -1 means "older" or
"before"). Date is separated into fields as follows:
'dm' - month (0 - January, 1 - February, .., 11 - December)
'dy' - year (four digits, for example 1999 or 2000)
'dd' - day (1...31)
If 'dt' is 'range', that means search withing given range of dates.
Variables 'db' and 'de' are used here and stands for beginning and end
date. Each date is string in the form dd/mm/yyyy, there dd is day,
mm is month and yyyy is four-digits year.
This is the example of FORM part where you can choose between different
time limiting options.
Limit results to pages published within a specified period of time. (Please select only one option)
or on
,
Between
and
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:
restop This section is included just before the search results. It's not a bad
idea to provide some common search results. You can do so by using the
next meta symbols:
$f - number of First document displayed on this page
$l - number of Last document displayed on this page
$t - Total number of found documents
$W - information about the number of word forms found
(e.g. if your query was 'html template' $W can be something like
'html: 10 template: 20')
and about words that was excluded from search
(e.g. 'if: stopword')
Below is an example of 'restop' section:
Search results:
$W
Displaying documents $f-$l of total $t found.
res This section is used for displaying various information about every
found document. The following meta symbols are used:
$DU Document URL
$DT Document Title
$DR Document Rating (as calculated by mnoGoSearch)
$DX Document teXt (the first couple of lines to give an idea
of what the document is about).
$DC Document Content-type (for example, text/html)
$DM Document Last-Modified date
$DS Document Size (in bytes)
$DN Document Number (in order of appearance)
$DD Document Description (from META DESCRIPTION tag)
$DE if non empty $DD then $DD else $DX
$DK Document Keywords (from META KEYWORDS tag)
$DY Document category with links,
i.e. /home/computers/software/www/
$CL Clone List (see section 'clone' for details)
Here is an example of res section:
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.
$DU ($DC) $DM
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.
The meta char used is:
$V - naVigator (links to previous/next pages)
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, is used, and on the first page there is no
previous page, so is used.
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:
Sorry, but search hasn't returned results.
Try to compose less restrictive search query or check spelling.
noquery
This section is displayed in case when user gived an empty query.
Below is an example of noquery section:
You haven't typed any word(s) to search for.
error This section is displayed in case some internal error occured while
searching. For example, database server is not running or so.
You may provide next meta symbol:
$E - Error text
Example of error section:
An error occured!
$E
There is also a special variables section, in which you can set up
some values for search. Note that database options work only for SQL
backend and do not matter for built-in text files support.
Like in indexer.conf, DBHost takes affect for
natively supported databases only and does not matter for ODBC databases.
In case of ODBC use DBName to specify ODBC DSN.
Special variables section usually looks like this:
RN is maximum random number generated if you are using $rN meta symbol. N is a
number in range from 0 to MAXRANDOM-1 (defined in search.h, default is 128).
Please provide "RN xxxx" for every $rN which you use in template.
Include in templates
--------------------
$if
You can use $if(another_template_file_name) meta symbol to include
another file into being proccessed one in any part of template.
For example, this will use top.htm as "top" section of search results:
$if(top.htm)
$iurl
You can use $iurl(http://myhostname/my_path?arguments) meta symbol
to include result of processing this URL. If search.cgi is compiled
with threads support, URL processing will be done in parallel with
search process.
WARNING: You can use $iurl ONLY in the following template sections:
, , , ,
, .
This is an example of $iurl usage:
$iurl(http://my.search.com/findit?query=$q&from=$pn)
Using several formats with one template
---------------------------------------
Since version 3.0.10 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.