Added some material about ICU chains.
[idzebra-moved-to-github.git] / doc / administration.xml
1 <chapter id="administration">
2  <!-- $Id: administration.xml,v 1.54 2007-12-19 09:30:29 adam Exp $ -->
3  <title>Administrating &zebra;</title>
4  <!-- ### It's a bit daft that this chapter (which describes half of
5           the configuration-file formats) is separated from
6           "recordmodel-grs.xml" (which describes the other half) by the
7           instructions on running zebraidx and zebrasrv.  Some careful
8           re-ordering is required here.
9  -->
10
11  <para>
12   Unlike many simpler retrieval systems, &zebra; supports safe, incremental
13   updates to an existing index.
14  </para>
15  
16  <para>
17   Normally, when &zebra; modifies the index it reads a number of records
18   that you specify.
19   Depending on your specifications and on the contents of each record
20   one the following events take place for each record:
21   <variablelist>
22    
23    <varlistentry>
24     <term>Insert</term>
25     <listitem>
26      <para>
27       The record is indexed as if it never occurred before.
28       Either the &zebra; system doesn't know how to identify the record or
29       &zebra; can identify the record but didn't find it to be already indexed.
30      </para>
31     </listitem>
32    </varlistentry>
33    <varlistentry>
34     <term>Modify</term>
35     <listitem>
36      <para>
37       The record has already been indexed.
38       In this case either the contents of the record or the location
39       (file) of the record indicates that it has been indexed before.
40      </para>
41     </listitem>
42    </varlistentry>
43    <varlistentry>
44     <term>Delete</term>
45     <listitem>
46      <para>
47       The record is deleted from the index. As in the
48       update-case it must be able to identify the record.
49      </para>
50     </listitem>
51    </varlistentry>
52   </variablelist>
53  </para>
54  
55  <para>
56   Please note that in both the modify- and delete- case the &zebra;
57   indexer must be able to generate a unique key that identifies the record 
58   in question (more on this below).
59  </para>
60  
61  <para>
62   To administrate the &zebra; retrieval system, you run the
63   <literal>zebraidx</literal> program.
64   This program supports a number of options which are preceded by a dash,
65   and a few commands (not preceded by dash).
66 </para>
67  
68  <para>
69   Both the &zebra; administrative tool and the &acro.z3950; server share a
70   set of index files and a global configuration file.
71   The name of the configuration file defaults to
72   <literal>zebra.cfg</literal>.
73   The configuration file includes specifications on how to index
74   various kinds of records and where the other configuration files
75   are located. <literal>zebrasrv</literal> and <literal>zebraidx</literal>
76   <emphasis>must</emphasis> be run in the directory where the
77   configuration file lives unless you indicate the location of the 
78   configuration file by option <literal>-c</literal>.
79  </para>
80  
81  <sect1 id="record-types">
82   <title>Record Types</title>
83   
84   <para>
85    Indexing is a per-record process, in which either insert/modify/delete
86    will occur. Before a record is indexed search keys are extracted from
87    whatever might be the layout the original record (sgml,html,text, etc..).
88    The &zebra; system currently supports two fundamental types of records:
89    structured and simple text.
90    To specify a particular extraction process, use either the
91    command line option <literal>-t</literal> or specify a
92    <literal>recordType</literal> setting in the configuration file.
93   </para>
94   
95  </sect1>
96  
97  <sect1 id="zebra-cfg">
98   <title>The &zebra; Configuration File</title>
99   
100   <para>
101    The &zebra; configuration file, read by <literal>zebraidx</literal> and
102    <literal>zebrasrv</literal> defaults to <literal>zebra.cfg</literal>
103    unless specified by <literal>-c</literal> option.
104   </para>
105   
106   <para>
107    You can edit the configuration file with a normal text editor.
108    parameter names and values are separated by colons in the file. Lines
109    starting with a hash sign (<literal>#</literal>) are
110    treated as comments.
111   </para>
112   
113   <para>
114    If you manage different sets of records that share common
115    characteristics, you can organize the configuration settings for each
116    type into "groups".
117    When <literal>zebraidx</literal> is run and you wish to address a
118    given group you specify the group name with the <literal>-g</literal>
119    option.
120    In this case settings that have the group name as their prefix 
121    will be used by <literal>zebraidx</literal>.
122    If no <literal>-g</literal> option is specified, the settings
123    without prefix are used.
124   </para>
125   
126   <para>
127    In the configuration file, the group name is placed before the option
128    name itself, separated by a dot (.). For instance, to set the record type
129    for group <literal>public</literal> to <literal>grs.sgml</literal>
130    (the &acro.sgml;-like format for structured records) you would write:
131   </para>
132   
133   <para>
134    <screen>
135     public.recordType: grs.sgml
136    </screen>   
137   </para>
138   
139   <para>
140    To set the default value of the record type to <literal>text</literal>
141    write:
142   </para>
143   
144   <para>
145    <screen>
146     recordType: text
147    </screen>
148   </para>
149   
150   <para>
151    The available configuration settings are summarized below. They will be
152    explained further in the following sections.
153   </para>
154   
155   <!--
156    FIXME - Didn't Adam make something to have multiple databases in multiple dirs...
157   -->
158   
159   <para>
160    <variablelist>
161     
162     <varlistentry>
163      <term>
164       <emphasis>group</emphasis>
165       .recordType[<emphasis>.name</emphasis>]:
166       <replaceable>type</replaceable>
167      </term>
168      <listitem>
169       <para>
170        Specifies how records with the file extension
171        <emphasis>name</emphasis> should be handled by the indexer.
172        This option may also be specified as a command line option
173        (<literal>-t</literal>). Note that if you do not specify a
174        <emphasis>name</emphasis>, the setting applies to all files.
175        In general, the record type specifier consists of the elements (each
176        element separated by dot), <emphasis>fundamental-type</emphasis>,
177        <emphasis>file-read-type</emphasis> and arguments. Currently, two
178        fundamental types exist, <literal>text</literal> and
179        <literal>grs</literal>.
180       </para>
181      </listitem>
182     </varlistentry>
183     <varlistentry>
184      <term><emphasis>group</emphasis>.recordId: 
185      <replaceable>record-id-spec</replaceable></term>
186      <listitem>
187       <para>
188        Specifies how the records are to be identified when updated. See
189        <xref linkend="locating-records"/>.
190       </para>
191      </listitem>
192     </varlistentry>
193     <varlistentry>
194      <term><emphasis>group</emphasis>.database:
195      <replaceable>database</replaceable></term>
196      <listitem>
197       <para>
198        Specifies the &acro.z3950; database name.
199        <!-- FIXME - now we can have multiple databases in one server. -H -->
200       </para>
201      </listitem>
202     </varlistentry>
203     <varlistentry>
204      <term><emphasis>group</emphasis>.storeKeys:
205      <replaceable>boolean</replaceable></term>
206      <listitem>
207       <para>
208        Specifies whether key information should be saved for a given
209        group of records. If you plan to update/delete this type of
210        records later this should be specified as 1; otherwise it
211        should be 0 (default), to save register space.
212        <!-- ### this is the first mention of "register" -->
213        See <xref linkend="file-ids"/>.
214       </para>
215      </listitem>
216     </varlistentry>
217     <varlistentry>
218      <term><emphasis>group</emphasis>.storeData:
219       <replaceable>boolean</replaceable></term>
220      <listitem>
221       <para>
222        Specifies whether the records should be stored internally
223        in the &zebra; system files.
224        If you want to maintain the raw records yourself,
225        this option should be false (0).
226        If you want &zebra; to take care of the records for you, it
227        should be true(1).
228       </para>
229      </listitem>
230     </varlistentry>
231     <varlistentry>
232      <!-- ### probably a better place to define "register" -->
233      <term>register: <replaceable>register-location</replaceable></term>
234      <listitem>
235       <para>
236        Specifies the location of the various register files that &zebra; uses
237        to represent your databases.
238        See <xref linkend="register-location"/>.
239       </para>
240      </listitem>
241     </varlistentry>
242     <varlistentry>
243      <term>shadow: <replaceable>register-location</replaceable></term>
244      <listitem>
245       <para>
246        Enables the <emphasis>safe update</emphasis> facility of &zebra;, and
247        tells the system where to place the required, temporary files.
248        See <xref linkend="shadow-registers"/>.
249       </para>
250      </listitem>
251     </varlistentry>
252     <varlistentry>
253      <term>lockDir: <replaceable>directory</replaceable></term>
254      <listitem>
255       <para>
256        Directory in which various lock files are stored.
257       </para>
258      </listitem>
259     </varlistentry>
260     <varlistentry>
261      <term>keyTmpDir: <replaceable>directory</replaceable></term>
262      <listitem>
263       <para>
264        Directory in which temporary files used during zebraidx's update
265        phase are stored. 
266       </para>
267      </listitem>
268     </varlistentry>
269     <varlistentry>
270      <term>setTmpDir: <replaceable>directory</replaceable></term>
271      <listitem>
272       <para>
273        Specifies the directory that the server uses for temporary result sets.
274        If not specified <literal>/tmp</literal> will be used.
275       </para>
276      </listitem>
277     </varlistentry>
278     <varlistentry>
279      <term>profilePath: <replaceable>path</replaceable></term>
280      <listitem>
281       <para>
282        Specifies a path of profile specification files. 
283        The path is composed of one or more directories separated by
284        colon. Similar to <literal>PATH</literal> for UNIX systems.
285       </para>
286      </listitem>
287     </varlistentry>
288
289      <varlistentry>
290       <term>modulePath: <replaceable>path</replaceable></term>
291       <listitem>
292        <para>
293         Specifies a path of record filter modules.
294         The path is composed of one or more directories separated by
295         colon. Similar to <literal>PATH</literal> for UNIX systems.
296         The 'make install' procedure typically puts modules in
297         <filename>/usr/local/lib/idzebra-2.0/modules</filename>.
298        </para>
299       </listitem>
300      </varlistentry>
301
302      <varlistentry>
303       <term>index: <replaceable>filename</replaceable></term>
304       <listitem>
305        <para>
306         Defines the filename which holds fields structure
307         definitions. If omitted, the file <filename>default.idx</filename>
308         is read.
309         Refer to <xref linkend="default-idx-file"/> for
310         more information.
311        </para>
312       </listitem>
313      </varlistentry>
314
315      <varlistentry>
316       <term>staticrank: <replaceable>integer</replaceable></term>
317       <listitem>
318        <para>
319         Enables whether static ranking is to be enabled (1) or
320         disabled (0). If omitted, it is disabled - corresponding
321         to a value of 0.
322         Refer to <xref linkend="administration-ranking-static"/> .
323        </para>
324       </listitem>
325      </varlistentry>
326
327
328      <varlistentry>
329       <term>estimatehits:: <replaceable>integer</replaceable></term>
330       <listitem>
331        <para>
332         Controls whether &zebra; should calculate approximite hit counts and
333         at which hit count it is to be enabled.
334         A value of 0 disables approximiate hit counts.
335         For a positive value approximaite hit count is enabled
336         if it is known to be larger than <replaceable>integer</replaceable>.
337        </para>
338        <para>
339         Approximate hit counts can also be triggered by a particular
340         attribute in a query.
341         Refer to <xref linkend="querymodel-zebra-global-attr-limit"/>.
342        </para>
343       </listitem>
344      </varlistentry>
345
346     <varlistentry>
347      <term>attset: <replaceable>filename</replaceable></term>
348      <listitem>
349       <para>
350         Specifies the filename(s) of attribute set files for use in
351         searching. In many configurations <filename>bib1.att</filename>
352         is used, but that is not required. If Classic Explain
353         attributes is to be used for searching,
354         <filename>explain.att</filename> must be given.
355         The path to att-files in general can be given using 
356         <literal>profilePath</literal> setting.
357         See also <xref linkend="attset-files"/>.
358       </para>
359      </listitem>
360     </varlistentry>
361     <varlistentry>
362      <term>memMax: <replaceable>size</replaceable></term>
363      <listitem>
364       <para>
365        Specifies <replaceable>size</replaceable> of internal memory
366        to use for the zebraidx program.
367        The amount is given in megabytes - default is 4 (4 MB).
368        The more memory, the faster large updates happen, up to about
369        half the free memory available on the computer.
370       </para>
371      </listitem>
372     </varlistentry>
373     <varlistentry>
374      <term>tempfiles: <replaceable>Yes/Auto/No</replaceable></term>
375      <listitem>
376       <para>
377        Tells zebra if it should use temporary files when indexing. The
378        default is Auto, in which case zebra uses temporary files only
379        if it would need more that <replaceable>memMax</replaceable> 
380        megabytes of memory. This should be good for most uses.
381       </para>
382      </listitem>
383     </varlistentry>
384
385     <varlistentry>
386      <term>root: <replaceable>dir</replaceable></term>
387      <listitem>
388       <para>
389        Specifies a directory base for &zebra;. All relative paths
390        given (in profilePath, register, shadow) are based on this
391        directory. This setting is useful if your &zebra; server
392        is running in a different directory from where
393        <literal>zebra.cfg</literal> is located.
394       </para>
395      </listitem>
396     </varlistentry>
397
398     <varlistentry>
399      <term>passwd: <replaceable>file</replaceable></term>
400      <listitem>
401       <para>
402        Specifies a file with description of user accounts for &zebra;.
403        The format is similar to that known to Apache's htpasswd files
404        and UNIX' passwd files. Non-empty lines not beginning with
405        # are considered account lines. There is one account per-line.
406        A line consists of fields separate by a single colon character.
407        First field is username, second is password.
408       </para>
409      </listitem>
410     </varlistentry>
411
412     <varlistentry>
413      <term>passwd.c: <replaceable>file</replaceable></term>
414      <listitem>
415       <para>
416        Specifies a file with description of user accounts for &zebra;.
417        File format is similar to that used by the passwd directive except
418        that the password are encrypted. Use Apache's htpasswd or similar
419        for maintenance.
420       </para>
421      </listitem>
422     </varlistentry>
423
424     <varlistentry>
425      <term>perm.<replaceable>user</replaceable>:
426      <replaceable>permstring</replaceable></term>
427      <listitem>
428       <para>
429        Specifies permissions (priviledge) for a user that are allowed
430        to access &zebra; via the passwd system. There are two kinds
431        of permissions currently: read (r) and write(w). By default
432        users not listed in a permission directive are given the read
433        privilege. To specify permissions for a user with no
434        username, or &acro.z3950; anonymous style use
435         <literal>anonymous</literal>. The permstring consists of
436        a sequence of characters. Include character <literal>w</literal>
437        for write/update access, <literal>r</literal> for read access and
438        <literal>a</literal> to allow anonymous access through this account.
439       </para>
440      </listitem>
441     </varlistentry>
442
443     <varlistentry>
444       <term>dbaccess <replaceable>accessfile</replaceable></term>
445       <listitem>
446         <para>
447           Names a file which lists database subscriptions for individual users.
448           The access file should consists of lines of the form <literal>username:
449           dbnames</literal>, where dbnames is a list of database names, seprated by
450           '+'. No whitespace is allowed in the database list.
451         </para>
452       </listitem>
453     </varlistentry>
454
455    </variablelist>
456   </para>
457   
458  </sect1>
459  
460  <sect1 id="locating-records">
461   <title>Locating Records</title>
462   
463   <para>
464    The default behavior of the &zebra; system is to reference the
465    records from their original location, i.e. where they were found when you
466    run <literal>zebraidx</literal>.
467    That is, when a client wishes to retrieve a record
468    following a search operation, the files are accessed from the place
469    where you originally put them - if you remove the files (without
470    running <literal>zebraidx</literal> again, the server will return
471    diagnostic number 14 (``System error in presenting records'') to
472    the client.
473   </para>
474   
475   <para>
476    If your input files are not permanent - for example if you retrieve
477    your records from an outside source, or if they were temporarily
478    mounted on a CD-ROM drive,
479    you may want &zebra; to make an internal copy of them. To do this,
480    you specify 1 (true) in the <literal>storeData</literal> setting. When
481    the &acro.z3950; server retrieves the records they will be read from the
482    internal file structures of the system.
483   </para>
484   
485  </sect1>
486  
487  <sect1 id="simple-indexing">
488   <title>Indexing with no Record IDs (Simple Indexing)</title>
489   
490   <para>
491    If you have a set of records that are not expected to change over time
492    you may can build your database without record IDs.
493    This indexing method uses less space than the other methods and
494    is simple to use. 
495   </para>
496   
497   <para>
498    To use this method, you simply omit the <literal>recordId</literal> entry
499    for the group of files that you index. To add a set of records you use
500    <literal>zebraidx</literal> with the <literal>update</literal> command. The
501    <literal>update</literal> command will always add all of the records that it
502    encounters to the index - whether they have already been indexed or
503    not. If the set of indexed files change, you should delete all of the
504    index files, and build a new index from scratch.
505   </para>
506   
507   <para>
508    Consider a system in which you have a group of text files called
509    <literal>simple</literal>.
510    That group of records should belong to a &acro.z3950; database called
511    <literal>textbase</literal>.
512    The following <literal>zebra.cfg</literal> file will suffice:
513   </para>
514   <para>
515    
516    <screen>
517     profilePath: /usr/local/idzebra/tab
518     attset: bib1.att
519     simple.recordType: text
520     simple.database: textbase
521    </screen>
522
523   </para>
524   
525   <para>
526    Since the existing records in an index can not be addressed by their
527    IDs, it is impossible to delete or modify records when using this method.
528   </para>
529   
530  </sect1>
531  
532  <sect1 id="file-ids">
533   <title>Indexing with File Record IDs</title>
534   
535   <para>
536    If you have a set of files that regularly change over time: Old files
537    are deleted, new ones are added, or existing files are modified, you
538    can benefit from using the <emphasis>file ID</emphasis>
539    indexing methodology.
540    Examples of this type of database might include an index of WWW
541    resources, or a USENET news spool area.
542    Briefly speaking, the file key methodology uses the directory paths
543    of the individual records as a unique identifier for each record.
544    To perform indexing of a directory with file keys, again, you specify
545    the top-level directory after the <literal>update</literal> command.
546    The command will recursively traverse the directories and compare
547    each one with whatever have been indexed before in that same directory.
548    If a file is new (not in the previous version of the directory) it
549    is inserted into the registers; if a file was already indexed and
550    it has been modified since the last update, the index is also
551    modified; if a file has been removed since the last
552    visit, it is deleted from the index.
553   </para>
554   
555   <para>
556    The resulting system is easy to administrate. To delete a record you
557    simply have to delete the corresponding file (say, with the
558    <literal>rm</literal> command). And to add records you create new
559    files (or directories with files). For your changes to take effect
560    in the register you must run <literal>zebraidx update</literal> with
561    the same directory root again. This mode of operation requires more
562    disk space than simpler indexing methods, but it makes it easier for
563    you to keep the index in sync with a frequently changing set of data.
564    If you combine this system with the <emphasis>safe update</emphasis>
565    facility (see below), you never have to take your server off-line for
566    maintenance or register updating purposes.
567   </para>
568   
569   <para>
570    To enable indexing with pathname IDs, you must specify
571    <literal>file</literal> as the value of <literal>recordId</literal>
572    in the configuration file. In addition, you should set
573    <literal>storeKeys</literal> to <literal>1</literal>, since the &zebra;
574    indexer must save additional information about the contents of each record
575    in order to modify the indexes correctly at a later time.
576   </para>
577   
578    <!--
579     FIXME - There must be a simpler way to do this with Adams string tags -H
580      -->
581
582   <para>
583    For example, to update records of group <literal>esdd</literal>
584    located below
585    <literal>/data1/records/</literal> you should type:
586    <screen>
587     $ zebraidx -g esdd update /data1/records
588    </screen>
589   </para>
590   
591   <para>
592    The corresponding configuration file includes:
593    <screen>
594     esdd.recordId: file
595     esdd.recordType: grs.sgml
596     esdd.storeKeys: 1
597    </screen>
598   </para>
599   
600   <note>
601    <para>You cannot start out with a group of records with simple
602     indexing (no record IDs as in the previous section) and then later
603     enable file record Ids. &zebra; must know from the first time that you
604     index the group that
605     the files should be indexed with file record IDs.
606    </para>
607    </note>
608   
609   <para>
610    You cannot explicitly delete records when using this method (using the
611    <literal>delete</literal> command to <literal>zebraidx</literal>. Instead
612    you have to delete the files from the file system (or move them to a
613    different location)
614    and then run <literal>zebraidx</literal> with the
615    <literal>update</literal> command.
616   </para>
617   <!-- ### what happens if a file contains multiple records? -->
618 </sect1>
619  
620  <sect1 id="generic-ids">
621   <title>Indexing with General Record IDs</title>
622   
623   <para>
624    When using this method you construct an (almost) arbitrary, internal
625    record key based on the contents of the record itself and other system
626    information. If you have a group of records that explicitly associates
627    an ID with each record, this method is convenient. For example, the
628    record format may contain a title or a ID-number - unique within the group.
629    In either case you specify the &acro.z3950; attribute set and use-attribute
630    location in which this information is stored, and the system looks at
631    that field to determine the identity of the record.
632   </para>
633   
634   <para>
635    As before, the record ID is defined by the <literal>recordId</literal>
636    setting in the configuration file. The value of the record ID specification
637    consists of one or more tokens separated by whitespace. The resulting
638    ID is represented in the index by concatenating the tokens and
639    separating them by ASCII value (1).
640   </para>
641   
642   <para>
643    There are three kinds of tokens:
644    <variablelist>
645     
646     <varlistentry>
647      <term>Internal record info</term>
648      <listitem>
649       <para>
650        The token refers to a key that is
651        extracted from the record. The syntax of this token is
652        <literal>(</literal> <emphasis>set</emphasis> <literal>,</literal>
653        <emphasis>use</emphasis> <literal>)</literal>,
654        where <emphasis>set</emphasis> is the
655        attribute set name <emphasis>use</emphasis> is the
656        name or value of the attribute.
657       </para>
658      </listitem>
659     </varlistentry>
660     <varlistentry>
661      <term>System variable</term>
662      <listitem>
663       <para>
664        The system variables are preceded by
665        
666        <screen>
667         $
668        </screen>
669        and immediately followed by the system variable name, which
670        may one of
671        <variablelist>
672         
673         <varlistentry>
674          <term>group</term>
675          <listitem>
676           <para>
677            Group name.
678           </para>
679          </listitem>
680         </varlistentry>
681         <varlistentry>
682          <term>database</term>
683          <listitem>
684           <para>
685            Current database specified.
686           </para>
687          </listitem>
688         </varlistentry>
689         <varlistentry>
690          <term>type</term>
691          <listitem>
692           <para>
693            Record type.
694           </para>
695          </listitem>
696         </varlistentry>
697        </variablelist>
698       </para>
699      </listitem>
700     </varlistentry>
701     <varlistentry>
702      <term>Constant string</term>
703      <listitem>
704       <para>
705        A string used as part of the ID &mdash; surrounded
706        by single- or double quotes.
707       </para>
708      </listitem>
709     </varlistentry>
710    </variablelist>
711   </para>
712   
713   <para>
714    For instance, the sample GILS records that come with the &zebra;
715    distribution contain a unique ID in the data tagged Control-Identifier.
716    The data is mapped to the &acro.bib1; use attribute Identifier-standard
717    (code 1007). To use this field as a record id, specify
718    <literal>(bib1,Identifier-standard)</literal> as the value of the
719    <literal>recordId</literal> in the configuration file.
720    If you have other record types that uses the same field for a
721    different purpose, you might add the record type
722    (or group or database name) to the record id of the gils
723    records as well, to prevent matches with other types of records.
724    In this case the recordId might be set like this:
725    
726    <screen>
727     gils.recordId: $type (bib1,Identifier-standard)
728    </screen>
729    
730   </para>
731   
732   <para>
733    (see <xref linkend="grs"/>
734     for details of how the mapping between elements of your records and
735     searchable attributes is established).
736   </para>
737   
738   <para>
739    As for the file record ID case described in the previous section,
740    updating your system is simply a matter of running
741    <literal>zebraidx</literal>
742    with the <literal>update</literal> command. However, the update with general
743    keys is considerably slower than with file record IDs, since all files
744    visited must be (re)read to discover their IDs. 
745   </para>
746   
747   <para>
748    As you might expect, when using the general record IDs
749    method, you can only add or modify existing records with the
750    <literal>update</literal> command.
751    If you wish to delete records, you must use the,
752    <literal>delete</literal> command, with a directory as a parameter.
753    This will remove all records that match the files below that root
754    directory.
755   </para>
756   
757  </sect1>
758  
759  <sect1 id="register-location">
760   <title>Register Location</title>
761   
762   <para>
763    Normally, the index files that form dictionaries, inverted
764    files, record info, etc., are stored in the directory where you run
765    <literal>zebraidx</literal>. If you wish to store these, possibly large,
766    files somewhere else, you must add the <literal>register</literal>
767    entry to the <literal>zebra.cfg</literal> file.
768    Furthermore, the &zebra; system allows its file
769    structures to span multiple file systems, which is useful for
770    managing very large databases. 
771   </para>
772   
773   <para>
774    The value of the <literal>register</literal> setting is a sequence
775    of tokens. Each token takes the form:
776    
777    <screen>
778     <emphasis>dir</emphasis><literal>:</literal><emphasis>size</emphasis> 
779    </screen>
780    
781    The <emphasis>dir</emphasis> specifies a directory in which index files
782    will be stored and the <emphasis>size</emphasis> specifies the maximum
783    size of all files in that directory. The &zebra; indexer system fills
784    each directory in the order specified and use the next specified
785    directories as needed.
786    The <emphasis>size</emphasis> is an integer followed by a qualifier
787    code, 
788    <literal>b</literal> for bytes,
789    <literal>k</literal> for kilobytes.
790    <literal>M</literal> for megabytes,
791    <literal>G</literal> for gigabytes.
792    Specifying a negative value disables the checking (it still needs the unit, 
793    use <literal>-1b</literal>).
794   </para>
795   
796   <para>
797    For instance, if you have allocated three disks for your register, and
798    the first disk is mounted
799    on <literal>/d1</literal> and has 2GB of free space, the
800    second, mounted on <literal>/d2</literal> has 3.6 GB, and the third,
801    on which you have more space than you bother to worry about, mounted on 
802    <literal>/d3</literal> you could put this entry in your configuration file:
803    
804    <screen>
805     register: /d1:2G /d2:3600M /d3:-1b
806    </screen>
807   </para>
808   
809   <para>
810    Note that &zebra; does not verify that the amount of space specified is
811    actually available on the directory (file system) specified - it is
812    your responsibility to ensure that enough space is available, and that
813    other applications do not attempt to use the free space. In a large
814    production system, it is recommended that you allocate one or more
815    file system exclusively to the &zebra; register files.
816   </para>
817   
818  </sect1>
819  
820  <sect1 id="shadow-registers">
821   <title>Safe Updating - Using Shadow Registers</title>
822   
823   <sect2 id="shadow-registers-description">
824    <title>Description</title>
825    
826    <para>
827     The &zebra; server supports <emphasis>updating</emphasis> of the index
828     structures. That is, you can add, modify, or remove records from
829     databases managed by &zebra; without rebuilding the entire index.
830     Since this process involves modifying structured files with various
831     references between blocks of data in the files, the update process
832     is inherently sensitive to system crashes, or to process interruptions:
833     Anything but a successfully completed update process will leave the
834     register files in an unknown state, and you will essentially have no
835     recourse but to re-index everything, or to restore the register files
836     from a backup medium.
837     Further, while the update process is active, users cannot be
838     allowed to access the system, as the contents of the register files
839     may change unpredictably.
840    </para>
841    
842    <para>
843     You can solve these problems by enabling the shadow register system in
844     &zebra;.
845     During the updating procedure, <literal>zebraidx</literal> will temporarily
846     write changes to the involved files in a set of "shadow
847     files", without modifying the files that are accessed by the
848     active server processes. If the update procedure is interrupted by a
849     system crash or a signal, you simply repeat the procedure - the
850     register files have not been changed or damaged, and the partially
851     written shadow files are automatically deleted before the new updating
852     procedure commences.
853    </para>
854    
855    <para>
856     At the end of the updating procedure (or in a separate operation, if
857     you so desire), the system enters a "commit mode". First,
858     any active server processes are forced to access those blocks that
859     have been changed from the shadow files rather than from the main
860     register files; the unmodified blocks are still accessed at their
861     normal location (the shadow files are not a complete copy of the
862     register files - they only contain those parts that have actually been
863     modified). If the commit process is interrupted at any point during the
864     commit process, the server processes will continue to access the
865     shadow files until you can repeat the commit procedure and complete
866     the writing of data to the main register files. You can perform
867     multiple update operations to the registers before you commit the
868     changes to the system files, or you can execute the commit operation
869     at the end of each update operation. When the commit phase has
870     completed successfully, any running server processes are instructed to
871     switch their operations to the new, operational register, and the
872     temporary shadow files are deleted.
873    </para>
874    
875   </sect2>
876   
877   <sect2 id="shadow-registers-how-to-use">
878    <title>How to Use Shadow Register Files</title>
879    
880    <para>
881     The first step is to allocate space on your system for the shadow
882     files.
883     You do this by adding a <literal>shadow</literal> entry to the
884     <literal>zebra.cfg</literal> file.
885     The syntax of the <literal>shadow</literal> entry is exactly the
886     same as for the <literal>register</literal> entry
887     (see <xref linkend="register-location"/>).
888      The location of the shadow area should be
889      <emphasis>different</emphasis> from the location of the main register
890      area (if you have specified one - remember that if you provide no
891      <literal>register</literal> setting, the default register area is the
892      working directory of the server and indexing processes).
893    </para>
894    
895    <para>
896     The following excerpt from a <literal>zebra.cfg</literal> file shows
897     one example of a setup that configures both the main register
898     location and the shadow file area.
899     Note that two directories or partitions have been set aside
900     for the shadow file area. You can specify any number of directories
901     for each of the file areas, but remember that there should be no
902     overlaps between the directories used for the main registers and the
903     shadow files, respectively.
904    </para>
905    <para>
906     
907     <screen>
908      register: /d1:500M
909      shadow: /scratch1:100M /scratch2:200M
910     </screen>
911     
912    </para>
913    
914    <para>
915     When shadow files are enabled, an extra command is available at the
916     <literal>zebraidx</literal> command line.
917     In order to make changes to the system take effect for the
918     users, you'll have to submit a "commit" command after a
919     (sequence of) update operation(s).
920    </para>
921    
922    <para>
923     
924     <screen>
925      $ zebraidx update /d1/records 
926      $ zebraidx commit
927     </screen>
928     
929    </para>
930    
931    <para>
932     Or you can execute multiple updates before committing the changes:
933    </para>
934    
935    <para>
936     
937     <screen>
938      $ zebraidx -g books update /d1/records  /d2/more-records
939      $ zebraidx -g fun update /d3/fun-records
940      $ zebraidx commit
941     </screen>
942     
943    </para>
944    
945    <para>
946     If one of the update operations above had been interrupted, the commit
947     operation on the last line would fail: <literal>zebraidx</literal>
948     will not let you commit changes that would destroy the running register.
949     You'll have to rerun all of the update operations since your last
950     commit operation, before you can commit the new changes.
951    </para>
952    
953    <para>
954     Similarly, if the commit operation fails, <literal>zebraidx</literal>
955     will not let you start a new update operation before you have
956     successfully repeated the commit operation.
957     The server processes will keep accessing the shadow files rather
958     than the (possibly damaged) blocks of the main register files
959     until the commit operation has successfully completed.
960    </para>
961    
962    <para>
963     You should be aware that update operations may take slightly longer
964     when the shadow register system is enabled, since more file access
965     operations are involved. Further, while the disk space required for
966     the shadow register data is modest for a small update operation, you
967     may prefer to disable the system if you are adding a very large number
968     of records to an already very large database (we use the terms
969     <emphasis>large</emphasis> and <emphasis>modest</emphasis>
970     very loosely here, since every application will have a
971     different perception of size).
972     To update the system without the use of the the shadow files,
973     simply run <literal>zebraidx</literal> with the <literal>-n</literal>
974     option (note that you do not have to execute the
975     <emphasis>commit</emphasis> command of <literal>zebraidx</literal>
976     when you temporarily disable the use of the shadow registers in
977     this fashion.
978     Note also that, just as when the shadow registers are not enabled,
979     server processes will be barred from accessing the main register
980     while the update procedure takes place.
981    </para>
982    
983   </sect2>
984   
985  </sect1>
986
987
988  <sect1 id="administration-ranking">
989   <title>Relevance Ranking and Sorting of Result Sets</title>
990
991   <sect2 id="administration-overview">
992    <title>Overview</title>
993    <para>
994     The default ordering of a result set is left up to the server,
995     which inside &zebra; means sorting in ascending document ID order. 
996     This is not always the order humans want to browse the sometimes
997     quite large hit sets. Ranking and sorting comes to the rescue.
998    </para>
999
1000    <para> 
1001     In cases where a good presentation ordering can be computed at
1002     indexing time, we can use a fixed <literal>static ranking</literal>
1003     scheme, which is provided for the <literal>alvis</literal>
1004     indexing filter. This defines a fixed ordering of hit lists,
1005     independently of the query issued. 
1006    </para>
1007
1008    <para>
1009     There are cases, however, where relevance of hit set documents is
1010     highly dependent on the query processed.
1011     Simply put, <literal>dynamic relevance ranking</literal> 
1012     sorts a set of retrieved records such that those most likely to be
1013     relevant to your request are retrieved first. 
1014     Internally, &zebra; retrieves all documents that satisfy your
1015     query, and re-orders the hit list to arrange them based on
1016     a measurement of similarity between your query and the content of
1017     each record. 
1018    </para>
1019
1020    <para>
1021     Finally, there are situations where hit sets of documents should be
1022     <literal>sorted</literal> during query time according to the
1023     lexicographical ordering of certain sort indexes created at
1024     indexing time.
1025    </para>
1026   </sect2>
1027
1028
1029  <sect2 id="administration-ranking-static">
1030   <title>Static Ranking</title>
1031   
1032    <para>
1033     &zebra; uses internally inverted indexes to look up term occurencies
1034     in documents. Multiple queries from different indexes can be
1035     combined by the binary boolean operations <literal>AND</literal>, 
1036     <literal>OR</literal> and/or <literal>NOT</literal> (which
1037     is in fact a binary <literal>AND NOT</literal> operation). 
1038     To ensure fast query execution
1039     speed, all indexes have to be sorted in the same order.
1040    </para>
1041    <para>
1042     The indexes are normally sorted according to document 
1043     <literal>ID</literal> in
1044     ascending order, and any query which does not invoke a special
1045     re-ranking function will therefore retrieve the result set in
1046     document 
1047     <literal>ID</literal>
1048     order.
1049    </para>
1050    <para>
1051     If one defines the 
1052     <screen>
1053     staticrank: 1 
1054     </screen> 
1055     directive in the main core &zebra; configuration file, the internal document
1056     keys used for ordering are augmented by a preceding integer, which
1057     contains the static rank of a given document, and the index lists
1058     are ordered 
1059     first by ascending static rank,
1060     then by ascending document <literal>ID</literal>.
1061     Zero
1062     is the ``best'' rank, as it occurs at the
1063     beginning of the list; higher numbers represent worse scores.
1064    </para>
1065    <para>
1066     The experimental <literal>alvis</literal> filter provides a
1067     directive to fetch static rank information out of the indexed &acro.xml;
1068     records, thus making <emphasis>all</emphasis> hit sets ordered
1069     after <emphasis>ascending</emphasis> static
1070     rank, and for those doc's which have the same static rank, ordered
1071     after <emphasis>ascending</emphasis> doc <literal>ID</literal>.
1072     See <xref linkend="record-model-alvisxslt"/> for the gory details.
1073    </para>
1074     </sect2>
1075
1076
1077  <sect2 id="administration-ranking-dynamic">
1078   <title>Dynamic Ranking</title>
1079    <para>
1080     In order to fiddle with the static rank order, it is necessary to
1081     invoke additional re-ranking/re-ordering using dynamic
1082     ranking or score functions. These functions return positive
1083     integer scores, where <emphasis>highest</emphasis> score is 
1084     ``best'';
1085     hit sets are sorted according to <emphasis>descending</emphasis> 
1086     scores (in contrary
1087     to the index lists which are sorted according to
1088     ascending rank number and document ID).
1089    </para>
1090    <para>
1091     Dynamic ranking is enabled by a directive like one of the
1092     following in the zebra configuration file (use only one of these a time!):
1093     <screen> 
1094     rank: rank-1        # default TDF-IDF like
1095     rank: rank-static   # dummy do-nothing
1096     </screen>
1097    </para>
1098  
1099    <para>
1100     Dynamic ranking is done at query time rather than
1101     indexing time (this is why we
1102     call it ``dynamic ranking'' in the first place ...)
1103     It is invoked by adding
1104     the &acro.bib1; relation attribute with
1105     value ``relevance'' to the &acro.pqf; query (that is,
1106     <literal>@attr&nbsp;2=102</literal>, see also  
1107     <ulink url="&url.z39.50;bib1.html">
1108      The &acro.bib1; Attribute Set Semantics</ulink>, also in 
1109       <ulink url="&url.z39.50.attset.bib1;">HTML</ulink>). 
1110     To find all articles with the word <literal>Eoraptor</literal> in
1111     the title, and present them relevance ranked, issue the &acro.pqf; query:
1112     <screen>
1113      @attr 2=102 @attr 1=4 Eoraptor
1114     </screen>
1115    </para>
1116
1117     <sect3 id="administration-ranking-dynamic-rank1">
1118      <title>Dynamically ranking using &acro.pqf; queries with the 'rank-1' 
1119       algorithm</title>
1120
1121    <para>
1122      The default <literal>rank-1</literal> ranking module implements a 
1123      TF/IDF (Term Frequecy over Inverse Document Frequency) like
1124      algorithm. In contrast to the usual defintion of TF/IDF
1125      algorithms, which only considers searching in one full-text
1126      index, this one works on multiple indexes at the same time.
1127      More precisely, 
1128      &zebra; does boolean queries and searches in specific addressed
1129      indexes (there are inverted indexes pointing from terms in the
1130      dictionary to documents and term positions inside documents). 
1131      It works like this:
1132      <variablelist>
1133       <varlistentry>
1134        <term>Query Components</term>
1135        <listitem>
1136         <para>
1137          First, the boolean query is dismantled into its principal components,
1138          i.e. atomic queries where one term is looked up in one index.
1139          For example, the query
1140          <screen>
1141         @attr 2=102 @and @attr 1=1010 Utah @attr 1=1018 Springer
1142          </screen>
1143          is a boolean AND between the atomic parts
1144          <screen>
1145        @attr 2=102 @attr 1=1010 Utah
1146          </screen>
1147           and
1148          <screen>
1149        @attr 2=102 @attr 1=1018 Springer
1150          </screen>
1151          which gets processed each for itself.
1152         </para>
1153        </listitem>
1154       </varlistentry>
1155
1156       <varlistentry>
1157        <term>Atomic hit lists</term>
1158        <listitem>
1159         <para>
1160          Second, for each atomic query, the hit list of documents is
1161          computed.
1162         </para>
1163         <para>
1164          In this example, two hit lists for each index  
1165          <literal>@attr 1=1010</literal>  and  
1166          <literal>@attr 1=1018</literal> are computed.
1167         </para>
1168        </listitem>
1169       </varlistentry>
1170
1171       <varlistentry>
1172        <term>Atomic scores</term>
1173        <listitem>
1174         <para>
1175          Third, each document in the hit list is assigned a score (_if_ ranking
1176          is enabled and requested in the query)  using a TF/IDF scheme.
1177         </para>
1178         <para>
1179          In this example, both atomic parts of the query assign the magic
1180          <literal>@attr 2=102</literal> relevance attribute, and are
1181          to be used in the relevance ranking functions. 
1182         </para>
1183         <para>
1184          It is possible to apply dynamic ranking on only parts of the
1185          &acro.pqf; query: 
1186          <screen>
1187           @and @attr 2=102 @attr 1=1010 Utah @attr 1=1018 Springer
1188          </screen>
1189          searches for all documents which have the term 'Utah' on the
1190          body of text, and which have the term 'Springer' in the publisher
1191          field, and sort them in the order of the relevance ranking made on
1192          the body-of-text index only. 
1193         </para>
1194        </listitem>
1195       </varlistentry>
1196
1197       <varlistentry>
1198        <term>Hit list merging</term>
1199        <listitem>
1200         <para>
1201          Fourth, the atomic hit lists are merged according to the boolean
1202          conditions to a final hit list of documents to be returned.
1203         </para>
1204         <para>
1205         This step is always performed, independently of the fact that
1206         dynamic ranking is enabled or not.
1207         </para>
1208        </listitem>
1209       </varlistentry>
1210
1211       <varlistentry>
1212        <term>Document score computation</term>
1213        <listitem>
1214         <para>
1215          Fifth, the total score of a document is computed as a linear
1216          combination of the atomic scores of the atomic hit lists
1217         </para>
1218         <para>
1219          Ranking weights may be used to pass a value to a ranking
1220          algorithm, using the non-standard &acro.bib1; attribute type 9.
1221          This allows one branch of a query to use one value while
1222          another branch uses a different one.  For example, we can search
1223          for <literal>utah</literal> in the 
1224          <literal>@attr 1=4</literal> index with weight 30, as
1225          well as in the <literal>@attr 1=1010</literal> index with weight 20:
1226          <screen>
1227          @attr 2=102 @or @attr 9=30 @attr 1=4 utah @attr 9=20 @attr 1=1010 city
1228          </screen>
1229         </para>
1230         <para>
1231          The default weight is
1232          sqrt(1000) ~ 34 , as the &acro.z3950; standard prescribes that the top score
1233          is 1000 and the bottom score is 0, encoded in integers.
1234         </para>
1235         <warning>
1236          <para>
1237           The ranking-weight feature is experimental. It may change in future
1238           releases of zebra. 
1239          </para>
1240         </warning>
1241        </listitem>
1242       </varlistentry>
1243
1244       <varlistentry>
1245        <term>Re-sorting of hit list</term>
1246        <listitem>
1247         <para>
1248          Finally, the final hit list is re-ordered according to scores.
1249         </para>
1250        </listitem>
1251       </varlistentry>
1252      </variablelist>
1253  
1254
1255 <!--
1256 Still need to describe the exact TF/IDF formula. Here's the info, need -->
1257 <!--to extract it in human readable form .. MC
1258
1259 static int calc (void *set_handle, zint sysno, zint staticrank,
1260                  int *stop_flag)
1261 {
1262     int i, lo, divisor, score = 0;
1263     struct rank_set_info *si = (struct rank_set_info *) set_handle;
1264
1265     if (!si->no_rank_entries)
1266         return -1;   /* ranking not enabled for any terms */
1267
1268     for (i = 0; i < si->no_entries; i++)
1269     {
1270         yaz_log(log_level, "calc: i=%d rank_flag=%d lo=%d",
1271                 i, si->entries[i].rank_flag, si->entries[i].local_occur);
1272         if (si->entries[i].rank_flag && (lo = si->entries[i].local_occur))
1273             score += (8+log2_int (lo)) * si->entries[i].global_inv *
1274                 si->entries[i].rank_weight;
1275     }
1276     divisor = si->no_rank_entries * (8+log2_int (si->last_pos/si->no_entries));
1277     score = score / divisor;
1278     yaz_log(log_level, "calc sysno=" ZINT_FORMAT " score=%d", sysno, score);
1279     if (score > 1000)
1280         score = 1000;
1281     /* reset the counts for the next term */
1282     for (i = 0; i < si->no_entries; i++)
1283         si->entries[i].local_occur = 0;
1284     return score;
1285 }
1286
1287
1288 where lo = si->entries[i].local_occur is the local documents term-within-index frequency, si->entries[i].global_inv represents the IDF part (computed in static void *begin()), and
1289 si->entries[i].rank_weight is the weight assigner per index (default 34, or set in the @attr 9=xyz magic)
1290
1291 Finally, the IDF part is computed as:
1292
1293 static void *begin (struct zebra_register *reg,
1294                     void *class_handle, RSET rset, NMEM nmem,
1295                     TERMID *terms, int numterms)
1296 {
1297     struct rank_set_info *si =
1298         (struct rank_set_info *) nmem_malloc (nmem,sizeof(*si));
1299     int i;
1300
1301     yaz_log(log_level, "rank-1 begin");
1302     si->no_entries = numterms;
1303     si->no_rank_entries = 0;
1304     si->nmem=nmem;
1305     si->entries = (struct rank_term_info *)
1306         nmem_malloc (si->nmem, sizeof(*si->entries)*numterms);
1307     for (i = 0; i < numterms; i++)
1308     {
1309         zint g = rset_count(terms[i]->rset);
1310         yaz_log(log_level, "i=%d flags=%s '%s'", i,
1311                 terms[i]->flags, terms[i]->name );
1312         if  (!strncmp (terms[i]->flags, "rank,", 5))
1313         {
1314             const char *cp = strstr(terms[i]->flags+4, ",w=");
1315             si->entries[i].rank_flag = 1;
1316             if (cp)
1317                 si->entries[i].rank_weight = atoi (cp+3);
1318             else
1319               si->entries[i].rank_weight = 34; /* sqrroot of 1000 */
1320             yaz_log(log_level, " i=%d weight=%d g="ZINT_FORMAT, i,
1321                      si->entries[i].rank_weight, g);
1322             (si->no_rank_entries)++;
1323         }
1324         else
1325             si->entries[i].rank_flag = 0;
1326         si->entries[i].local_occur = 0;  /* FIXME */
1327         si->entries[i].global_occur = g;
1328         si->entries[i].global_inv = 32 - log2_int (g);
1329         yaz_log(log_level, " global_inv = %d g = " ZINT_FORMAT,
1330                 (int) (32-log2_int (g)), g);
1331         si->entries[i].term = terms[i];
1332         si->entries[i].term_index=i;
1333         terms[i]->rankpriv = &(si->entries[i]);
1334     }
1335     return si;
1336 }
1337
1338
1339 where g = rset_count(terms[i]->rset) is the count of all documents in this specific index hit list, and the IDF part then is
1340
1341  si->entries[i].global_inv = 32 - log2_int (g);
1342    -->
1343
1344    </para>
1345
1346
1347     <para>
1348     The <literal>rank-1</literal> algorithm
1349     does not use the static rank 
1350     information in the list keys, and will produce the same ordering
1351     with or without static ranking enabled.
1352     </para>
1353  
1354
1355     <!--
1356     <sect3 id="administration-ranking-dynamic-rank1">
1357      <title>Dynamically ranking &acro.pqf; queries with the 'rank-static' 
1358       algorithm</title>
1359     <para>
1360     The dummy <literal>rank-static</literal> reranking/scoring
1361     function returns just 
1362     <literal>score = max int - staticrank</literal>
1363     in order to preserve the static ordering of hit sets that would
1364     have been produced had it not been invoked.
1365     Obviously, to combine static and dynamic ranking usefully,
1366     it is necessary
1367     to make a new ranking 
1368     function; this is left
1369     as an exercise for the reader. 
1370    </para>
1371     </sect3>
1372     -->
1373  
1374    <warning>
1375      <para>
1376       <literal>Dynamic ranking</literal> is not compatible
1377       with <literal>estimated hit sizes</literal>, as all documents in
1378       a hit set must be accessed to compute the correct placing in a
1379       ranking sorted list. Therefore the use attribute setting
1380       <literal>@attr&nbsp;2=102</literal> clashes with 
1381       <literal>@attr&nbsp;9=integer</literal>. 
1382      </para>
1383    </warning>  
1384
1385    <!--
1386     we might want to add ranking like this:
1387     UNPUBLISHED:
1388     Simple BM25 Extension to Multiple Weighted Fields
1389     Stephen Robertson, Hugo Zaragoza and Michael Taylor
1390     Microsoft Research
1391     ser@microsoft.com
1392     hugoz@microsoft.com
1393     mitaylor2microsoft.com
1394    -->
1395
1396     </sect3>
1397
1398     <sect3 id="administration-ranking-dynamic-cql">
1399      <title>Dynamically ranking &acro.cql; queries</title>
1400      <para>
1401       Dynamic ranking can be enabled during sever side &acro.cql;
1402       query expansion by adding <literal>@attr&nbsp;2=102</literal>
1403       chunks to the &acro.cql; config file. For example
1404       <screen>
1405        relationModifier.relevant                = 2=102
1406       </screen>
1407       invokes dynamic ranking each time a &acro.cql; query of the form 
1408       <screen>
1409        Z> querytype cql
1410        Z> f alvis.text =/relevant house
1411       </screen>
1412       is issued. Dynamic ranking can also be automatically used on
1413       specific &acro.cql; indexes by (for example) setting
1414       <screen>
1415        index.alvis.text                        = 1=text 2=102
1416       </screen>
1417       which then invokes dynamic ranking each time a &acro.cql; query of the form 
1418       <screen>
1419        Z> querytype cql
1420        Z> f alvis.text = house
1421       </screen>
1422       is issued.
1423      </para>
1424      
1425     </sect3>
1426
1427     </sect2>
1428
1429
1430  <sect2 id="administration-ranking-sorting">
1431   <title>Sorting</title>
1432    <para>
1433      &zebra; sorts efficiently using special sorting indexes
1434      (type=<literal>s</literal>; so each sortable index must be known
1435      at indexing time, specified in the configuration of record
1436      indexing.  For example, to enable sorting according to the &acro.bib1;
1437      <literal>Date/time-added-to-db</literal> field, one could add the line
1438      <screen>
1439         xelm /*/@created               Date/time-added-to-db:s
1440      </screen>
1441      to any <literal>.abs</literal> record-indexing configuration file.
1442      Similarly, one could add an indexing element of the form
1443      <screen><![CDATA[       
1444       <z:index name="date-modified" type="s">
1445        <xsl:value-of select="some/xpath"/>
1446       </z:index>
1447       ]]></screen>
1448      to any <literal>alvis</literal>-filter indexing stylesheet.
1449      </para>
1450      <para>
1451       Indexing can be specified at searching time using a query term
1452       carrying the non-standard
1453       &acro.bib1; attribute-type <literal>7</literal>.  This removes the
1454       need to send a &acro.z3950; <literal>Sort Request</literal>
1455       separately, and can dramatically improve latency when the client
1456       and server are on separate networks.
1457       The sorting part of the query is separate from the rest of the
1458       query - the actual search specification - and must be combined
1459       with it using OR.
1460      </para>
1461      <para>
1462       A sorting subquery needs two attributes: an index (such as a
1463       &acro.bib1; type-1 attribute) specifying which index to sort on, and a
1464       type-7 attribute whose value is be <literal>1</literal> for
1465       ascending sorting, or <literal>2</literal> for descending.  The
1466       term associated with the sorting attribute is the priority of
1467       the sort key, where <literal>0</literal> specifies the primary
1468       sort key, <literal>1</literal> the secondary sort key, and so
1469       on.
1470      </para>
1471     <para>For example, a search for water, sort by title (ascending),
1472     is expressed by the &acro.pqf; query
1473      <screen>
1474      @or @attr 1=1016 water @attr 7=1 @attr 1=4 0
1475      </screen>
1476       whereas a search for water, sort by title ascending, 
1477      then date descending would be
1478      <screen>
1479      @or @or @attr 1=1016 water @attr 7=1 @attr 1=4 0 @attr 7=2 @attr 1=30 1
1480      </screen>
1481     </para>
1482     <para>
1483      Notice the fundamental differences between <literal>dynamic
1484      ranking</literal> and <literal>sorting</literal>: there can be
1485      only one ranking function defined and configured; but multiple
1486      sorting indexes can be specified dynamically at search
1487      time. Ranking does not need to use specific indexes, so
1488      dynamic ranking can be enabled and disabled without
1489      re-indexing; whereas, sorting indexes need to be
1490      defined before indexing.
1491      </para>
1492
1493  </sect2>
1494
1495
1496  </sect1>
1497
1498  <sect1 id="administration-extended-services">
1499   <title>Extended Services: Remote Insert, Update and Delete</title>
1500   
1501    <note>
1502     <para>
1503      Extended services are only supported when accessing the &zebra;
1504      server using the <ulink url="&url.z39.50;">&acro.z3950;</ulink>
1505      protocol. The <ulink url="&url.sru;">&acro.sru;</ulink> protocol does
1506      not support extended services.
1507     </para>
1508    </note>
1509    
1510   <para>
1511     The extended services are not enabled by default in zebra - due to the
1512     fact that they modify the system. &zebra; can be configured
1513     to allow anybody to
1514     search, and to allow only updates for a particular admin user
1515     in the main zebra configuration file <filename>zebra.cfg</filename>.
1516     For user <literal>admin</literal>, you could use:
1517     <screen>
1518      perm.anonymous: r
1519      perm.admin: rw
1520      passwd: passwordfile
1521     </screen>
1522     And in the password file 
1523     <filename>passwordfile</filename>, you have to specify users and
1524     encrypted passwords as colon separated strings. 
1525     Use a tool like <filename>htpasswd</filename> 
1526     to maintain the encrypted passwords. 
1527     <screen> 
1528      admin:secret
1529     </screen>
1530     It is essential to configure  &zebra; to store records internally, 
1531     and to support
1532     modifications and deletion of records:
1533     <screen>
1534      storeData: 1
1535      storeKeys: 1
1536     </screen>
1537     The general record type should be set to any record filter which
1538     is able to parse &acro.xml; records, you may use any of the two
1539     declarations (but not both simultaneously!)
1540     <screen>    
1541      recordType: grs.xml
1542      # recordType: alvis.filter_alvis_config.xml
1543     </screen>
1544     To enable transaction safe shadow indexing,
1545     which is extra important for this kind of operation, set
1546     <screen>
1547      shadow: directoryname: size (e.g. 1000M)
1548     </screen>
1549      See <xref linkend="zebra-cfg"/> for additional information on
1550      these configuration options.
1551    </para>
1552    <note>
1553     <para>
1554      It is not possible to carry information about record types or
1555      similar to &zebra; when using extended services, due to
1556      limitations of the <ulink url="&url.z39.50;">&acro.z3950;</ulink>
1557      protocol. Therefore, indexing filters can not be chosen on a
1558      per-record basis. One and only one general &acro.xml; indexing filter
1559      must be defined.  
1560      <!-- but because it is represented as an OID, we would need some
1561      form of proprietary mapping scheme between record type strings and
1562      OIDs. -->
1563      <!--
1564      However, as a minimum, it would be extremely useful to enable
1565      people to use &acro.marc21;, assuming grs.marcxml.marc21 as a record
1566      type.  
1567      -->
1568     </para>
1569    </note>
1570
1571
1572    <sect2 id="administration-extended-services-z3950">
1573     <title>Extended services in the &acro.z3950; protocol</title>
1574
1575     <para>
1576      The <ulink url="&url.z39.50;">&acro.z3950;</ulink> standard allows
1577      servers to accept special binary <emphasis>extended services</emphasis>
1578      protocol packages, which may be used to insert, update and delete
1579      records into servers. These carry  control and update
1580      information to the servers, which are encoded in seven package fields: 
1581     </para>
1582
1583     <table id="administration-extended-services-z3950-table" frame="top">
1584      <title>Extended services &acro.z3950; Package Fields</title>
1585       <tgroup cols="3">
1586        <thead>
1587        <row>
1588          <entry>Parameter</entry>
1589          <entry>Value</entry>
1590          <entry>Notes</entry>
1591         </row>
1592       </thead>
1593        <tbody>
1594         <row>
1595          <entry><literal>type</literal></entry>
1596          <entry><literal>'update'</literal></entry>
1597          <entry>Must be set to trigger extended services</entry>
1598         </row>
1599         <row>
1600          <entry><literal>action</literal></entry>
1601          <entry><literal>string</literal></entry>
1602         <entry>
1603          Extended service action type with 
1604          one of four possible values: <literal>recordInsert</literal>,
1605          <literal>recordReplace</literal>,
1606          <literal>recordDelete</literal>,
1607          and <literal>specialUpdate</literal>
1608         </entry>
1609         </row>
1610         <row>
1611          <entry><literal>record</literal></entry>
1612          <entry><literal>&acro.xml; string</literal></entry>
1613          <entry>An &acro.xml; formatted string containing the record</entry>
1614         </row>
1615        <row>
1616         <entry><literal>syntax</literal></entry>
1617         <entry><literal>'xml'</literal></entry>
1618         <entry>XML/SUTRS/MARC. GRS-1 not supported.
1619          The default filter (record type) as given by recordType in
1620          zebra.cfg is used to parse the record.</entry>
1621        </row>
1622         <row>
1623          <entry><literal>recordIdOpaque</literal></entry>
1624          <entry><literal>string</literal></entry>
1625          <entry>
1626          Optional client-supplied, opaque record
1627          identifier used under insert operations.
1628         </entry>
1629         </row>
1630         <row>
1631          <entry><literal>recordIdNumber </literal></entry>
1632          <entry><literal>positive number</literal></entry>
1633          <entry>&zebra;'s internal system number,
1634          not allowed for  <literal>recordInsert</literal> or 
1635          <literal>specialUpdate</literal> actions which result in fresh
1636          record inserts.
1637         </entry>
1638         </row>
1639         <row>
1640          <entry><literal>databaseName</literal></entry>
1641          <entry><literal>database identifier</literal></entry>
1642         <entry>
1643          The name of the database to which the extended services should be 
1644          applied.
1645         </entry>
1646         </row>
1647       </tbody>
1648       </tgroup>
1649      </table>
1650
1651
1652    <para>
1653     The <literal>action</literal> parameter can be any of 
1654     <literal>recordInsert</literal> (will fail if the record already exists),
1655     <literal>recordReplace</literal> (will fail if the record does not exist),
1656     <literal>recordDelete</literal> (will fail if the record does not
1657        exist), and
1658     <literal>specialUpdate</literal> (will insert or update the record
1659        as needed, record deletion is not possible).
1660    </para>
1661
1662     <para>
1663      During all actions, the
1664      usual rules for internal record ID generation apply, unless an
1665      optional <literal>recordIdNumber</literal> &zebra; internal ID or a
1666     <literal>recordIdOpaque</literal> string identifier is assigned. 
1667      The default ID generation is
1668      configured using the <literal>recordId:</literal> from
1669      <filename>zebra.cfg</filename>.  
1670      See <xref linkend="zebra-cfg"/>.   
1671     </para>
1672
1673    <para>
1674     Setting of the <literal>recordIdNumber</literal> parameter, 
1675     which must be an existing &zebra; internal system ID number, is not
1676     allowed during any  <literal>recordInsert</literal> or 
1677      <literal>specialUpdate</literal> action resulting in fresh record
1678     inserts.
1679     </para>
1680
1681     <para>
1682      When retrieving existing
1683      records indexed with &acro.grs1; indexing filters, the &zebra; internal 
1684      ID number is returned in the field
1685     <literal>/*/id:idzebra/localnumber</literal> in the namespace
1686     <literal>xmlns:id="http://www.indexdata.dk/zebra/"</literal>,
1687     where it can be picked up for later record updates or deletes. 
1688     </para>
1689  
1690     <para>
1691      A new element set for retrieval of internal record
1692      data has been added, which can be used to access minimal records
1693      containing only the <literal>recordIdNumber</literal> &zebra;
1694      internal ID, or the <literal>recordIdOpaque</literal> string
1695      identifier. This works for any indexing filter used.
1696      See <xref linkend="special-retrieval"/>.
1697     </para>
1698
1699    <para>
1700      The <literal>recordIdOpaque</literal> string parameter
1701      is an client-supplied, opaque record
1702      identifier, which may be  used under 
1703      insert, update and delete operations. The
1704      client software is responsible for assigning these to
1705      records.      This identifier will
1706      replace zebra's own automagic identifier generation with a unique
1707      mapping from <literal>recordIdOpaque</literal> to the 
1708      &zebra; internal <literal>recordIdNumber</literal>.
1709      <emphasis>The opaque <literal>recordIdOpaque</literal> string
1710      identifiers
1711       are not visible in retrieval records, nor are
1712       searchable, so the value of this parameter is
1713       questionable. It serves mostly as a convenient mapping from
1714       application domain string identifiers to &zebra; internal ID's.
1715      </emphasis> 
1716     </para>
1717    </sect2>
1718
1719    
1720  <sect2 id="administration-extended-services-yaz-client">
1721   <title>Extended services from yaz-client</title>
1722
1723    <para>
1724     We can now start a yaz-client admin session and create a database:
1725    <screen>
1726     <![CDATA[
1727      $ yaz-client localhost:9999 -u admin/secret
1728      Z> adm-create
1729      ]]>
1730    </screen>
1731     Now the <literal>Default</literal> database was created,
1732     we can insert an &acro.xml; file (esdd0006.grs
1733     from example/gils/records) and index it:
1734    <screen>  
1735     <![CDATA[
1736      Z> update insert id1234 esdd0006.grs
1737      ]]>
1738    </screen>
1739     The 3rd parameter - <literal>id1234</literal> here -
1740       is the  <literal>recordIdOpaque</literal> package field.
1741    </para>
1742    <para>
1743     Actually, we should have a way to specify "no opaque record id" for
1744     yaz-client's update command.. We'll fix that.
1745    </para>
1746    <para>
1747     The newly inserted record can be searched as usual:
1748     <screen>
1749     <![CDATA[
1750      Z> f utah
1751      Sent searchRequest.
1752      Received SearchResponse.
1753      Search was a success.
1754      Number of hits: 1, setno 1
1755      SearchResult-1: term=utah cnt=1
1756      records returned: 0
1757      Elapsed: 0.014179
1758      ]]>
1759     </screen>
1760    </para>
1761    <para>
1762      Let's delete the beast, using the same 
1763      <literal>recordIdOpaque</literal> string parameter:
1764     <screen>
1765     <![CDATA[
1766      Z> update delete id1234
1767      No last record (update ignored)
1768      Z> update delete 1 esdd0006.grs
1769      Got extended services response
1770      Status: done
1771      Elapsed: 0.072441
1772      Z> f utah
1773      Sent searchRequest.
1774      Received SearchResponse.
1775      Search was a success.
1776      Number of hits: 0, setno 2
1777      SearchResult-1: term=utah cnt=0
1778      records returned: 0
1779      Elapsed: 0.013610
1780      ]]>
1781      </screen>
1782     </para>
1783     <para>
1784     If shadow register is enabled in your
1785     <filename>zebra.cfg</filename>,
1786     you must run the adm-commit command
1787     <screen>
1788     <![CDATA[
1789      Z> adm-commit
1790      ]]>
1791     </screen>
1792      after each update session in order write your changes from the
1793      shadow to the life register space.
1794    </para>
1795  </sect2>
1796
1797   
1798  <sect2 id="administration-extended-services-yaz-php">
1799   <title>Extended services from yaz-php</title>
1800
1801    <para>
1802     Extended services are also available from the &yaz; &acro.php; client layer. An
1803     example of an &yaz;-&acro.php; extended service transaction is given here:
1804     <screen>
1805     <![CDATA[
1806      $record = '<record><title>A fine specimen of a record</title></record>';
1807
1808      $options = array('action' => 'recordInsert',
1809                       'syntax' => 'xml',
1810                       'record' => $record,
1811                       'databaseName' => 'mydatabase'
1812                      );
1813
1814      yaz_es($yaz, 'update', $options);
1815      yaz_es($yaz, 'commit', array());
1816      yaz_wait();
1817
1818      if ($error = yaz_error($yaz))
1819        echo "$error";
1820      ]]>
1821     </screen>  
1822     </para>
1823     </sect2>
1824  </sect1>
1825
1826 </chapter>
1827
1828  <!-- Keep this comment at the end of the file
1829  Local variables:
1830  mode: sgml
1831  sgml-omittag:t
1832  sgml-shorttag:t
1833  sgml-minimize-attributes:nil
1834  sgml-always-quote-attributes:t
1835  sgml-indent-step:1
1836  sgml-indent-data:t
1837  sgml-parent-document: "zebra.xml"
1838  sgml-local-catalogs: nil
1839  sgml-namecase-general:t
1840  End:
1841  -->