# Character sets

## Supported character sets

DataparkSearch supports almost all known 8 bit character sets as well as some multi-byte charsets including Korean euc-kr, Chinese big5 and gb2312, Japanese shift-jis, euc-jp and iso-2022-jp, as well as UTF-8. Some multi-byte character sets are not supported by default, because the conversion tables for them are rather large that leads to increase of the executable files size. See `configure` parameters to enable support for these charsets.

DataparkSearch also supports the following Macintosh character sets: MacCE, MacCroatian, MacGreek, MacRoman, MacTurkish, MacIceland, MacRomania, MacThai, MacArabic, MacHebrew, MacCyrillic, MacGujarati.

&groups;

## Character sets aliases

Each charset is recognized by a number of its aliases. Web servers can return the same charset in different notation. For example, iso-8859-2, iso8859-2, latin2 are the same charsets. There is support for charsets names aliases which search engine can understand:

&csalias;

## Recoding

`indexer` recodes all documents to the character set specified in the `LocalCharset` command in your `indexer.conf` file. Internally recoding is implemented using Unicode. Please note that if some recoding can't convert a character directly from one charset to another, DataparkSearch will use HTML numeric character references to escape this character (i.e. in form &#NNN; where NNN - a character code in Unicode). Thus, for any `LocalCharset` you do not lost any information about indexed documents, but on `LocalCharset` selection depend the database volume you will get after indexing.

## Recoding at search time

You may display search results in any charset supported by DataparkSearch. Use `BrowserCharset` command in `search.htm` to select charset for search results. This charset may be different from `LocalCharset` specified. All recodings will done automatically.

## Document charset detection

indexer detects document character set in this order:

1. "Content-type: text/html; charset=xxx"

2. <META NAME="Content-Type" CONTENT="text/html; charset=xxx">

   Selection of this variant may be switch off by command: `GuesserUseMeta no` in your `indexer.conf`.

3. Defaults from "Charset" field in Common Parameters

## Automatic charset guesser

DataparkSearch has an automatic charset and language guesser. It currently recognizes more than 100 various charsets and languages. Charset and language detection is implemented using "N-Gram-Based Text Categorization" technique. There is a number of so called "language map" files, one for each language-charset pair. They are installed under `/usr/local/dpsearch/etc/langmap/` directory by default. Take a look there to check the list of currently provided charset-language pairs. Guesser works fine for texts bigger than 500 characters. Shorter texts may not be guessed well.

### `LangMapFile` command

Load language map for charset and language guesser from the given file. You may specify either absolute file name or a name relative to DataparkSearch `/etc` directory. You may use several `LangMapFile` commands.

    LangMapFile langmap/en.ascii.lm

### Build your own language maps

To build your own language map use
`dpguesser` utility. In addition, your need to collect file with language samples in charset desired. For new language map creation, use the following command:

            dpguesser -p -c charset -l language < FILENAME > language.charset.lm

You can also use `dpguesser` utility for guessing document's language and charset by existing language maps. To do this, use following command:

            dpguesser [-n maxhits] < FILENAME

For some languages, it may be used few different charset. To convert from one charset supported by DataparkSearch to another, use
`dpconv` utility.

            dpconv [OPTIONS] -f charset_from -t charset_to [configfile] < infile > outfile

You may also specyfy -e switch for `dpconv` to use HTML escape entities for input, and -E switch - for output.

By default, both `dpguesser` and `dpconv` utilities is installed into `/usr/local/dpsearch/sbin/` directory.

DataparkSearch can update language and charset maps automatically while indexing, if remote server is supply exactly specified language and charset with pages. To enable this function, specify the following command in your `indexer.conf` file:

    LangMapUpdate yes

By default, DataparkSearch uses only first 8192 bytes of each file indexed to detect language and charset. You may change this value using `GuesserBytes` command. Use value of 0 to use all text from document indexed.

    GuesserBytes 16384

## Default charset

Use `RemoteCharset` command in `indexer.conf` to choose the default charset of indexed servers.

## Default Language

You can set default language for Servers by using `DefaultLang` `indexer.conf` variable. This is useful while restricting search by URL language.

    DefaultLang <string>

Default language for server. Can be used if you need language restriction while doing search.

    DefaultLang en

## `LocalCharset` command

Defines the charset which will be used to store data in database. All other character sets will be recoded into given charset. Take a look into for detailed explanation how to choose a `LocalCharset` depending on languages used on your site(s). This command should be used once and takes global effect for the config file. Take a look into documentation to check whole list of supported charsets. Default LocalCharset is iso-8859-1 (latin1).

    LocalCharset koi8-r

## `ForceIISCharset1251` command

This option is useful for users which deals with Cyrillic content and broken (or misconfigured ?) Microsoft IIS web servers, which tends to not report charset correctly. This is really dirty hack, but if this option is turned on it is assumed that all servers which reports as 'Microsoft' or 'IIS' have content in Windows-1251 charset. This command should be used only once in configuration file and takes global effect. Default: no

    ForceIISCharset1251 yes

## `RemoteCharset` command

    RemoteCharset <charset>

`<charset>` is default character set for the server in next `Server`, `Realm` or `Subnet` command(s). This is required only for "bad" servers that do not send information about charset in header: "Content-type: text/html; charset=some_charset" and do not have <META NAME="Content" Content="text/html; charset="some_charset"> Can be set before every `Server`, `Realm` or `Subnet` command and takes effect till the end of config file or till next `RemoteCharset` command. Default value is iso-8859-1 (latin1).

    RemoteCharset iso-8859-5

## `URLCharset` command

    URLCharset <charset>

`<charset>` is character set for the URL argument in next `Server`, `Realm` or `URL` command(s). This command specify character set only for arguments in commands follow and havn't effect on charset detection for indexing pages. Have less priority than `RemoteCharset`. Can be set before every `Server`, `Realm` or `URL` command and takes effect till the end of config file or till next `URLCharset` command. Default value is ISO-8859-1 (latin1).

    URLCharset KOI8-R

## `CharsToEscape` command

    CharsToEscape "\"&<>![]"

Use this command in your search template to specify the list of characters to escape for $&(x) search template meta-variables.