Previous: , Up: Databases   [Contents][Index]


4.3.12.3 Virtual Databases

A virtual database is a collection of several regular databases. When a search is performed on a virtual database, it returns matches from the constituent databases.

Virtual databases can be used for grouping. For example a virtual database may include all dictionaries translating from English to Norwegian. Another one may include thesauri for English.

Yet another common use for virtual databases is to select different output markup depending on whether ‘OPTION MIME’ was requested by the user.

Technically, a virtual database is defined by specifying

  handler "virtual";

in the database definition. This is a built-in module, so you must not use the load-module statement.

The names of the member databases (the databases to be included to this one) are supplied using the database statements:

Database: database name [mime | nomime]

Specifies the database to be included as a member of this virtual database. The name argument supplies the name of the database (as set by the name statement in its definition).

Optional second argument may be used to restrict the use of this database to the given state of the ‘MIME’ option. Databases marked with ‘mime’ will be used only if the OPTION MIME command has been given for the current session. Databases marked with ‘nomime’ will be used only if this command has not been issued.

The following example defines a virtual database for translations from English to several other languages:

database {
  name "English Translating Database";
  info "Translations from English to other languages";
  handler "virtual";
  database "en-sw";
  database "en-no";
  database "en-pl";
}  

It is supposed, that databases ‘en-sw’, ‘en-no’, and ‘en-pl’ are defined elsewhere in the configuration.

Another example illustrates how to define a database that will select the format of the articles depending on whether the client requests MIME output. Suppose that the configuration defines two dictionaries: ‘thes_plain’, with a thesaurus formatted in plaintext, and ‘thes_html’, with the same thesaurus, but formatted in HTML. The following database will return plaintext responses by default and HTML responses after the OPTION MIME command:

database {
  name "thesaurus";
  handler "virtual";
  database thes_plain nomime;
  database thes_html mime;
}

Notice, that in this case it makes sense to define member databases as invisible, to avoid duplicate matches. E.g.:

database {
  name "thes_pain";
  visible no;
  ...
}  
database {
  name "thes_html";
  visible no;
  ...
}  

To determine description (whether short or long) for a virtual database, the following algorithm is used. If the ‘description’ (or, for long description, ‘info’) statement is present in the ‘database’ block, its value is used. Otherwise, the server obtains descriptions of each member database that is visible in the current ‘OPTION MIME’ state. If all databases return the same value, it is used. Otherwise, empty string is used.

Practically, that means that when defining a collection virtual database (as in the first example above), you are better off supplying both ‘description’ and ‘info’ statements.

On the other hand, when defining a mime-switching virtual database with two members (as in the second example), you can safely omit both statements: dicod will pick the value from the currently active member database.


Previous: Database Visibility, Up: Databases   [Contents][Index]