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