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