# 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 use `BrowserCharset` command to choose a charset which will be used to display search results. `BrowserCharset` may differ from `LocalCharset`, DataparkSearch will recode all data automaticaly.

## 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.

### 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

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

DataparkSearch has an ability to update language and charset maps automatically while indexing, if remote server supply with pages exactly specified language and charset. To enable this function, specify command

    LangMapUpdate yes

in your `indexer.conf` file.

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.

## Recoding during search

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.