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