Chapter 10. mnoGoSearch templates

Table of Contents
Introduction
Processing instructions
Statements
Comments
Data types
Selection statements
Iteration statements
Jump statements
Compound statements
Variable declarations
Expression statements
Functions
The string class
The ENV class
The RESULT class
The QUERYWORD class
The DOCUMENT class
Security issues

Introduction

mnoGoSearch users can fully customize the search results look and feel by editing the template file search.htm which resides in the /etc/ directory of your mnoGoSearch installation.

Processing instructions

mnoGoSearch template file is an HTML file with processing instruction blocks. The text outside of processing instruction blocks is printed as is. The text inside processing instruction blocks is interpreted as a C/C++ alike program.

Note: Template files are not limited to HTML format only. They can have any text based formats, e.g. XML, plain text, etc.

Example:


<?mnogosearch
  cout << "Content-Type: text/html; charset=utf-8\r\n\r\n";
?>
<html>
  <head>
    <title>Example</title>
  </head>
  <body>
  <?mnogosearch
    cout << "Hello!\n";
  ?>
  </body>
</html>
  

The fragments <?mnogosearch .. ?> are processing instruction blocks. They consist of statements.

Statements

The following statement types are supported:


<statement> ::= <expression-statement>
              | <compound-statement>
              | <selection-statement>
              | <iteration-statement>
              | <jump-statement>

Comments

mnoGoSearch supports single-line (C++ style) and multi-line (C style) comments inside processing instruction blocks:


  <?mnogosearch
    cout << "Test\n"; // This is a single-line comment
    /*
      This is a
      multi-line comment.
    */
    cout << "One more test\n";
  ?>
  

Data types

mnoGoSearch supports the following built-in standard C data types:

as well as built-in classes:

Selection statements

Selection statements are the if..else blocks.

Note: The switch statement is not supported. It will be added in the future versions.

Section statements implement the following grammar:


<selection-statement> ::= if ( <expression> ) <statement>
                        | if ( <expression> ) <statement> else <statement>

Iteration statements

Iteration statements are the while, and do and for loops:


<iteration-statement> ::= while ( <expression> ) <statement>
                        | do <statement> while ( <expression> )
                        | for ( {<declaration> | <expression>}? ; { <expression> }? ; {<expression>}? ) <statement>

Jump statements


<jump-statement> ::= continue ;
                   | break ;

Compound statements

Compound statements are code blocks inside curly brackets that can have optional variable declarations followed by optional nested statements.


<compound-statement> ::= '{' {<declaration>}* {<statement>}* '}'

Variable declarations


<declaration> ::= <type-specifier> {<init-declarator>}* ;

<init-declarator> ::= <identifier>
                    | <identifier> = <initializer>

<initializer> ::= <assignment-expression>

<type-specifier> ::= char
                   | int
                   | double
                   | <class-name>

Note: mnoGoSearch currently does not support the following data types: short, long, float, signed, unsigned, struct, union, enum, typedef.

Expression statements

Expression statements consist of variable assignments, function calls, as well as operator and method invocations.


<expression-statement> ::= { <expression> }? ;

Primary expression


<primary-expression> ::= <identifier>
                       | <literal>
                       | ( <expression> )

Postfix expression


<postfix-expression> ::= <primary-expression>
                       | <primary-expression> <function-call-arguments>
                       | <primary-expression> . <identifier> <function-call-arguments>
                       | <primary-expression> ++
                       | <primary-expression> --

<function-call-argument> ::= <assignment-expression>

<function-call-argument-list> ::= <function-call-argument> {, <function-call-argument>}*

<function-call-arguments> ::= ( <function-call-argument-list>? )

Note: As of version 3.4.1, function arguments are limited to variables and literals only. Passing other kinds of expressions as function and method call arguments will be added in the future versions.

Unary expression


<unary-expression> ::= <postfix-expression>
                     | <unary-operator> <cast-expression>
                     | ++ <unary-expression>
                     | -- <unary-expression>

<unary-operator> ::= +
                   | -
                   | ~
                   | !

Assignment expression


<assignment-expression> ::= <conditional-expression>
                          | <unary-expression> <assignment-operator> <assignment-expression>

<assignment-operator> ::= =
                        | *=
                        | /=
                        | %=
                        | +=
                        | -=
                        | <<=
                        | >>=
                        | &=
                        | ^=
                        | |=

Functions

The string class

Strings are objects that represent sequences of single-byte characters.

Strings have no any character set assumption. All methods of the string class operate in term of bytes.

string methods

The ENV class

The ENV class represents an environment - a global context (configuration) in which to search the database created by indexer.

ENV methods

The RESULT class

The RESULT represent a result of a search query.

RESULT methods

The QUERYWORD class

The QUERYWORD class is designed to present query words (search terms) found in the search query typed by the used, as well as their statistics in a search result set.

QUERYWORD methods

The DOCUMENT class

DOCUMENT is used to display cached copies, as well as to include external documents.

ENV methods

Security issues

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