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