added more information on character mapping
[idzebra-moved-to-github.git] / doc / field-structure.xml
1  <chapter id="fields-and-charsets">
2   <!-- $Id: field-structure.xml,v 1.8 2006-11-28 13:05:57 marc Exp $ -->
3   <title>Field Structure and Character Sets
4   </title>
5   
6   <para>
7    In order to provide a flexible approach to national character set
8    handling, Zebra allows the administrator to configure the set up the
9    system to handle any 8-bit character set &mdash; including sets that
10    require multi-octet diacritics or other multi-octet characters. The
11    definition of a character set includes a specification of the
12    permissible values, their sort order (this affects the display in the
13    SCAN function), and relationships between upper- and lowercase
14    characters. Finally, the definition includes the specification of
15    space characters for the set.
16   </para>
17
18   <para>
19    The operator can define different character sets for different fields,
20    typical examples being standard text fields, numerical fields, and
21    special-purpose fields such as WWW-style linkages (URx).
22   </para>
23
24   <section id="default-idx-file">
25    <title>The default.idx file</title>
26    <para>
27     The field types, and hence character sets, are associated with data
28     elements by the .abs files (see above).
29     The file <literal>default.idx</literal>
30     provides the association between field type codes (as used in the .abs
31     files) and the character map files (with the .chr suffix). The format
32     of the .idx file is as follows
33    </para>
34
35    <para>
36     <variablelist>
37
38      <varlistentry>
39       <term>index <replaceable>field type code</replaceable></term>
40       <listitem>
41        <para>
42         This directive introduces a new search index code.
43         The argument is a one-character code to be used in the
44         .abs files to select this particular index type. An index, roughly,
45         corresponds to a particular structure attribute during search. Refer
46         to <xref linkend="zebrasrv-search"/>.
47        </para>
48       </listitem></varlistentry>
49      <varlistentry>
50       <term>sort <replaceable>field code type</replaceable></term>
51       <listitem>
52        <para>
53         This directive introduces a 
54         sort index. The argument is a one-character code to be used in the
55         .abs fie to select this particular index type. The corresponding
56         use attribute must be used in the sort request to refer to this
57         particular sort index. The corresponding character map (see below)
58         is used in the sort process.
59        </para>
60       </listitem></varlistentry>
61      <varlistentry>
62       <term>completeness <replaceable>boolean</replaceable></term>
63       <listitem>
64        <para>
65         This directive enables or disables complete field indexing.
66         The value of the <replaceable>boolean</replaceable> should be 0
67         (disable) or 1. If completeness is enabled, the index entry will
68         contain the complete contents of the field (up to a limit), with words
69         (non-space characters) separated by single space characters
70         (normalized to " " on display). When completeness is
71         disabled, each word is indexed as a separate entry. Complete subfield
72         indexing is most useful for fields which are typically browsed (eg.
73         titles, authors, or subjects), or instances where a match on a
74         complete subfield is essential (eg. exact title searching). For fields
75         where completeness is disabled, the search engine will interpret a
76         search containing space characters as a word proximity search.
77        </para>
78       </listitem></varlistentry>
79
80      <varlistentry id="default.idx.firstinfield">
81       <term>firstinfield <replaceable>boolean</replaceable></term>
82       <listitem>
83        <para>
84         This directive enables or disables first-in-field indexing.
85         The value of the <replaceable>boolean</replaceable> should be 0
86         (disable) or 1. 
87        </para>
88       </listitem></varlistentry>
89
90      <varlistentry id="default.idx.alwaysmatches">
91       <term>alwaysmatches <replaceable>boolean</replaceable></term>
92       <listitem>
93        <para>
94         This directive enables or disables alwaysmatches indexing.
95         The value of the <replaceable>boolean</replaceable> should be 0
96         (disable) or 1. 
97        </para>
98       </listitem></varlistentry>
99
100      <varlistentry>
101       <term>charmap <replaceable>filename</replaceable></term>
102       <listitem>
103        <para>
104         This is the filename of the character
105         map to be used for this index for field type.
106         See <xref linkend="character-map-files"/> for details.
107        </para>
108       </listitem></varlistentry>
109     </variablelist>
110    </para>
111   </section>
112
113   <section id="character-map-files">
114    <title>The character map file format</title>
115    <para>
116     The character map files are used to define the word tokenization
117     and character normalization performed before inserting text into
118     the inverse indexes. Zebra ships with the predefined character map
119     files <filename>tab/*.chr</filename>. Users are allowed to add
120     and/or modify maps according to their needs.  
121    </para>
122
123    <table id="querymodel-attribute-sets-table" frame="top">
124      <title>Character maps predefined in Zebra</title>
125       <tgroup cols="3">
126        <thead>
127         <row>
128          <entry>File name</entry>
129          <entry>Intended type</entry>
130          <entry>Description</entry>
131         </row>
132        </thead>
133        <tbody>
134         <row>
135          <entry><literal>numeric.chr</literal></entry>
136          <entry><literal>:n</literal></entry>
137          <entry>Numeric digit tokenization and normalization map. All
138          characters not in the set <literal>-{0-9}.,</literal> will be
139          suppressed. Note that floating point numbers are processed
140          fine, but scientific exponential numbers are trashed.</entry>
141         </row>
142         <row>
143          <entry><literal>scan.chr</literal></entry>
144          <entry><literal>:w or :p</literal></entry>
145          <entry>Word tokenization char map for Scandinavian
146          languages. This one resembles the generic word tokenization
147          character map <literal>tab/string.chr</literal>, the main
148          differences are sorting of the special characters 
149         <literal>üzæäøöå</literal> and equivalence maps according to
150          Scandinavian language rules.</entry>
151         </row>
152         <row>
153          <entry><literal>string.chr</literal></entry>
154          <entry><literal>:w or :p</literal></entry>
155          <entry>General word tokenization and normalization character
156          map, mostly useful for English texts. Use this to derive your
157          own language tokenization and normalization derivatives.</entry>
158         </row>
159         <row>
160          <entry><literal>urx.chr</literal></entry>
161          <entry><literal>:u</literal></entry>
162          <entry>URL parsing and tokenization character map.</entry>
163         </row>
164         <row>
165          <entry><literal>@</literal></entry>
166          <entry><literal>:0</literal></entry>
167          <entry>Do-nothing character map used for literal binary
168          indexing. There is no existing file associated to it, and
169          there is no normalization or tokenization performed at all.</entry>
170         </row>
171       </tbody>
172      </tgroup>
173    </table>
174
175    <para>
176     The contents of the character map files are structured as follows:
177     <variablelist>
178
179      <varlistentry>
180       <term>lowercase <replaceable>value-set</replaceable></term>
181       <listitem>
182        <para>
183         This directive introduces the basic value set of the field type.
184         The format is an ordered list (without spaces) of the
185         characters which may occur in "words" of the given type.
186         The order of the entries in the list determines the
187         sort order of the index. In addition to single characters, the
188         following combinations are legal:
189        </para>
190
191        <para>
192
193         <itemizedlist>
194          <listitem>
195           <para>
196            Backslashes may be used to introduce three-digit octal, or
197            two-digit hex representations of single characters
198            (preceded by <literal>x</literal>).
199            In addition, the combinations
200            \\, \\r, \\n, \\t, \\s (space &mdash; remember that real
201            space-characters may not occur in the value definition), and
202            \\ are recognized, with their usual interpretation.
203           </para>
204          </listitem>
205
206          <listitem>
207           <para>
208            Curly braces {} may be used to enclose ranges of single
209            characters (possibly using the escape convention described in the
210            preceding point), eg. {a-z} to introduce the
211            standard range of ASCII characters.
212            Note that the interpretation of such a range depends on
213            the concrete representation in your local, physical character set.
214           </para>
215          </listitem>
216
217          <listitem>
218           <para>
219            paranthesises () may be used to enclose multi-byte characters -
220            eg. diacritics or special national combinations (eg. Spanish
221            "ll"). When found in the input stream (or a search term),
222            these characters are viewed and sorted as a single character, with a
223            sorting value depending on the position of the group in the value
224            statement.
225           </para>
226          </listitem>
227
228         </itemizedlist>
229
230        </para>
231        <para>
232         For example, <literal>scan.chr</literal> contains the following
233         lowercase normalization and sorting order:
234         <screen>
235          lowercase {0-9}{a-y}üzæäøöå
236         </screen>
237        </para>
238       </listitem></varlistentry>
239      <varlistentry>
240       <term>uppercase <replaceable>value-set</replaceable></term>
241       <listitem>
242        <para>
243         This directive introduces the
244         upper-case equivalences to the value set (if any). The number and
245         order of the entries in the list should be the same as in the
246         <literal>lowercase</literal> directive.
247        </para>
248        <para>
249         For example, <literal>scan.chr</literal> contains the following
250         uppercase equivalent:
251         <screen>
252          uppercase {0-9}{A-Y}ÜZÆÄØÖÅ
253         </screen>
254        </para>
255       </listitem></varlistentry>
256      <varlistentry>
257       <term>space <replaceable>value-set</replaceable></term>
258       <listitem>
259        <para>
260         This directive introduces the character
261         which separate words in the input stream. Depending on the
262         completeness mode of the field in question, these characters either
263         terminate an index entry, or delimit individual "words" in
264         the input stream. The order of the elements is not significant &mdash;
265         otherwise the representation is the same as for the
266         <literal>uppercase</literal> and <literal>lowercase</literal>
267         directives.
268        </para>
269        <para>
270         For example, <literal>scan.chr</literal> contains the following
271         space instruction:
272         <screen><![CDATA[
273          space {\001-\040}!"#$%&'\()*+,-./:;<=>?@\[\\]^_`\{|}~
274         ]]></screen>
275        </para>
276       </listitem></varlistentry>
277      <varlistentry>
278       <term>map <replaceable>value-set</replaceable>
279        <replaceable>target</replaceable></term>
280       <listitem>
281        <para>
282         This directive introduces a mapping between each of the
283         members of the value-set on the left to the character on the
284         right. The character on the right must occur in the value
285         set (the <literal>lowercase</literal> directive) of the
286         character set, but it may be a parenthesis-enclosed
287         multi-octet character. This directive may be used to map
288         diacritics to their base characters, or to map HTML-style
289         character-representations to their natural form, etc. The
290         map directive can also be used to ignore leading articles in
291         searching and/or sorting, and to perform other special
292         transformations. See section <xref
293          linkend="leading-articles"/>.
294        </para>
295        <para>
296         For example, <literal>scan.chr</literal> contains the following
297         map instructions among others, to make sure that HTML entity
298         encoded  Danish special characters are mapped to the
299         equivalent Latin-1 characters:
300         <screen><![CDATA[
301          map (&aelig;)      æ
302          map (&oslash;)     ø
303          map (&aring;)      å
304         ]]></screen>
305        </para>
306       </listitem></varlistentry>
307      <varlistentry>
308       <term>equivalent <replaceable>value-set</replaceable></term>
309       <listitem>
310        <para>
311         This directive introduces equivalence classes of characters
312         and/or strings for sorting purposes only. It resembles the map
313         directive, but does not affect search and retrieval indexing,
314         but only sorting order under present requests. 
315        </para>
316        <para>
317         For example, <literal>scan.chr</literal> contains the following
318         equivalent sorting instructions, which can be uncommented:
319         <screen><![CDATA[
320          # equivalent æä(ae)
321          # equivalent øö(oe)
322          # equivalent å(aa)
323          # equivalent uü
324         ]]></screen>
325        </para>
326       </listitem></varlistentry>
327     </variablelist>
328    </para>
329   </section>
330   <section id="leading-articles">
331    <title>Ignoring leading articles</title>
332    <para>
333     In addition to specifying sort orders, space (blank) handling,
334     and upper/lowercase folding, you can also use the character map
335     files to make Zebra ignore leading articles in sorting records,
336     or when doing complete field searching.
337    </para>
338    <para>
339     This is done using the <literal>map</literal> directive in the
340     character map file. In a nutshell, what you do is map certain
341     sequences of characters, when they occur <emphasis> in the
342      beginning of a field</emphasis>, to a space. Assuming that the
343     character "@" is defined as a space character in your file, you
344     can do:
345     <screen>
346      map (^The\s) @
347      map (^the\s) @
348     </screen>
349     The effect of these directives is to map either 'the' or 'The',
350     followed by a space character, to a space. The hat ^ character
351     denotes beginning-of-field only when complete-subfield indexing
352     or sort indexing is taking place; otherwise, it is treated just
353     as any other character.
354    </para>
355    <para>
356     Because the <literal>default.idx</literal> file can be used to
357     associate different character maps with different indexing types
358     -- and you can create additional indexing types, should the need
359     arise -- it is possible to specify that leading articles should
360     be ignored either in sorting, in complete-field searching, or
361     both.
362    </para>
363    <para>
364     If you ignore certain prefixes in sorting, then these will be
365     eliminated from the index, and sorting will take place as if
366     they weren't there. However, if you set the system up to ignore
367     certain prefixes in <emphasis>searching</emphasis>, then these
368     are deleted both from the indexes and from query terms, when the
369     client specifies complete-field searching. This has the effect
370     that a search for 'the science journal' and 'science journal'
371     would both produce the same results.
372    </para>
373   </section>
374
375  </chapter>
376  <!-- Keep this comment at the end of the file
377  Local variables:
378  mode: sgml
379  sgml-omittag:t
380  sgml-shorttag:t
381  sgml-minimize-attributes:nil
382  sgml-always-quote-attributes:t
383  sgml-indent-step:1
384  sgml-indent-data:t
385  sgml-parent-document: "zebra.xml"
386  sgml-local-catalogs: nil
387  sgml-namecase-general:t
388  End:
389  -->