1 <chapter id="administration">
2 <!-- $Id: administration.xml,v 1.46 2006-10-11 12:23:24 adam Exp $ -->
3 <title>Administrating Zebra</title>
4 <!-- ### It's a bit daft that this chapter (which describes half of
5 the configuration-file formats) is separated from
6 "recordmodel-grs.xml" (which describes the other half) by the
7 instructions on running zebraidx and zebrasrv. Some careful
8 re-ordering is required here.
12 Unlike many simpler retrieval systems, Zebra supports safe, incremental
13 updates to an existing index.
17 Normally, when Zebra modifies the index it reads a number of records
19 Depending on your specifications and on the contents of each record
20 one the following events take place for each record:
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.
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.
47 The record is deleted from the index. As in the
48 update-case it must be able to identify the record.
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).
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).
69 Both the Zebra administrative tool and the Z39.50 server share a
70 set of index files and a global configuration file.
71 The name of the configuration file defaults to
72 <literal>zebra.cfg</literal>.
73 The configuration file includes specifications on how to index
74 various kinds of records and where the other configuration files
75 are located. <literal>zebrasrv</literal> and <literal>zebraidx</literal>
76 <emphasis>must</emphasis> be run in the directory where the
77 configuration file lives unless you indicate the location of the
78 configuration file by option <literal>-c</literal>.
81 <sect1 id="record-types">
82 <title>Record Types</title>
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.
97 <sect1 id="zebra-cfg">
98 <title>The Zebra Configuration File</title>
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.
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
114 If you manage different sets of records that share common
115 characteristics, you can organize the configuration settings for each
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>
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.
127 In the configuration file, the group name is placed before the option
128 name itself, separated by a dot (.). For instance, to set the record type
129 for group <literal>public</literal> to <literal>grs.sgml</literal>
130 (the SGML-like format for structured records) you would write:
135 public.recordType: grs.sgml
140 To set the default value of the record type to <literal>text</literal>
151 The available configuration settings are summarized below. They will be
152 explained further in the following sections.
156 FIXME - Didn't Adam make something to have multiple databases in multiple dirs...
164 <emphasis>group</emphasis>
165 .recordType[<emphasis>.name</emphasis>]:
166 <replaceable>type</replaceable>
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>.
184 <term><emphasis>group</emphasis>.recordId:
185 <replaceable>record-id-spec</replaceable></term>
188 Specifies how the records are to be identified when updated. See
189 <xref linkend="locating-records"/>.
194 <term><emphasis>group</emphasis>.database:
195 <replaceable>database</replaceable></term>
198 Specifies the Z39.50 database name.
199 <!-- FIXME - now we can have multiple databases in one server. -H -->
204 <term><emphasis>group</emphasis>.storeKeys:
205 <replaceable>boolean</replaceable></term>
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"/>.
218 <term><emphasis>group</emphasis>.storeData:
219 <replaceable>boolean</replaceable></term>
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
232 <!-- ### probably a better place to define "register" -->
233 <term>register: <replaceable>register-location</replaceable></term>
236 Specifies the location of the various register files that Zebra uses
237 to represent your databases.
238 See <xref linkend="register-location"/>.
243 <term>shadow: <replaceable>register-location</replaceable></term>
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"/>.
253 <term>lockDir: <replaceable>directory</replaceable></term>
256 Directory in which various lock files are stored.
261 <term>keyTmpDir: <replaceable>directory</replaceable></term>
264 Directory in which temporary files used during zebraidx's update
270 <term>setTmpDir: <replaceable>directory</replaceable></term>
273 Specifies the directory that the server uses for temporary result sets.
274 If not specified <literal>/tmp</literal> will be used.
279 <term>profilePath: <replaceable>path</replaceable></term>
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.
290 <term>modulePath: <replaceable>path</replaceable></term>
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>.
303 <term>staticrank: <replaceable>integer</replaceable></term>
306 Enables whether static ranking is to be enabled (1) or
307 disabled (0). If omitted, it is disabled - corresponding
309 Refer to <xref linkend="administration-ranking-static"/> .
316 <term>estimatehits:: <replaceable>integer</replaceable></term>
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>.
326 Approximate hit counts can also be triggered by a particular
327 attribute in a query.
328 Refer to <xref linkend="querymodel-zebra-attr-approx"/>.
334 <term>attset: <replaceable>filename</replaceable></term>
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"/>.
349 <term>memMax: <replaceable>size</replaceable></term>
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.
361 <term>tempfiles: <replaceable>Yes/Auto/No</replaceable></term>
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.
373 <term>root: <replaceable>dir</replaceable></term>
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.
386 <term>passwd: <replaceable>file</replaceable></term>
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.
400 <term>passwd.c: <replaceable>file</replaceable></term>
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
412 <term>perm.<replaceable>user</replaceable>:
413 <replaceable>permstring</replaceable></term>
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 Z39.50 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.
431 <term>dbaccess <replaceable>accessfile</replaceable></term>
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.
447 <sect1 id="locating-records">
448 <title>Locating Records</title>
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
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 Z39.50 server retrieves the records they will be read from the
469 internal file structures of the system.
474 <sect1 id="simple-indexing">
475 <title>Indexing with no Record IDs (Simple Indexing)</title>
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
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.
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 Z39.50 database called
498 <literal>textbase</literal>.
499 The following <literal>zebra.cfg</literal> file will suffice:
504 profilePath: /usr/local/idzebra/tab
506 simple.recordType: text
507 simple.database: textbase
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.
519 <sect1 id="file-ids">
520 <title>Indexing with File Record IDs</title>
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.
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.
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.
566 FIXME - There must be a simpler way to do this with Adams string tags -H
570 For example, to update records of group <literal>esdd</literal>
572 <literal>/data1/records/</literal> you should type:
574 $ zebraidx -g esdd update /data1/records
579 The corresponding configuration file includes:
582 esdd.recordType: grs.sgml
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
592 the files should be indexed with file record IDs.
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
601 and then run <literal>zebraidx</literal> with the
602 <literal>update</literal> command.
604 <!-- ### what happens if a file contains multiple records? -->
607 <sect1 id="generic-ids">
608 <title>Indexing with General Record IDs</title>
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 Z39.50 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.
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).
630 There are three kinds of tokens:
634 <term>Internal record info</term>
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.
648 <term>System variable</term>
651 The system variables are preceded by
656 and immediately followed by the system variable name, which
669 <term>database</term>
672 Current database specified.
689 <term>Constant string</term>
692 A string used as part of the ID — surrounded
693 by single- or double quotes.
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 Bib-1 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:
714 gils.recordId: $type (bib1,Identifier-standard)
720 (see <xref linkend="grs"/>
721 for details of how the mapping between elements of your records and
722 searchable attributes is established).
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.
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
746 <sect1 id="register-location">
747 <title>Register Location</title>
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.
761 The value of the <literal>register</literal> setting is a sequence
762 of tokens. Each token takes the form:
765 <emphasis>dir</emphasis><literal>:</literal><emphasis>size</emphasis>.
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
775 <literal>b</literal> for bytes,
776 <literal>k</literal> for kilobytes.
777 <literal>M</literal> for megabytes,
778 <literal>G</literal> for gigabytes.
782 For instance, if you have allocated two disks for your register, and
783 the first disk is mounted
784 on <literal>/d1</literal> and has 2GB of free space and the
785 second, mounted on <literal>/d2</literal> has 3.6 GB, you could
786 put this entry in your configuration file:
789 register: /d1:2G /d2:3600M
795 Note that Zebra does not verify that the amount of space specified is
796 actually available on the directory (file system) specified - it is
797 your responsibility to ensure that enough space is available, and that
798 other applications do not attempt to use the free space. In a large
799 production system, it is recommended that you allocate one or more
800 file system exclusively to the Zebra register files.
805 <sect1 id="shadow-registers">
806 <title>Safe Updating - Using Shadow Registers</title>
808 <sect2 id="shadow-registers-description">
809 <title>Description</title>
812 The Zebra server supports <emphasis>updating</emphasis> of the index
813 structures. That is, you can add, modify, or remove records from
814 databases managed by Zebra without rebuilding the entire index.
815 Since this process involves modifying structured files with various
816 references between blocks of data in the files, the update process
817 is inherently sensitive to system crashes, or to process interruptions:
818 Anything but a successfully completed update process will leave the
819 register files in an unknown state, and you will essentially have no
820 recourse but to re-index everything, or to restore the register files
821 from a backup medium.
822 Further, while the update process is active, users cannot be
823 allowed to access the system, as the contents of the register files
824 may change unpredictably.
828 You can solve these problems by enabling the shadow register system in
830 During the updating procedure, <literal>zebraidx</literal> will temporarily
831 write changes to the involved files in a set of "shadow
832 files", without modifying the files that are accessed by the
833 active server processes. If the update procedure is interrupted by a
834 system crash or a signal, you simply repeat the procedure - the
835 register files have not been changed or damaged, and the partially
836 written shadow files are automatically deleted before the new updating
841 At the end of the updating procedure (or in a separate operation, if
842 you so desire), the system enters a "commit mode". First,
843 any active server processes are forced to access those blocks that
844 have been changed from the shadow files rather than from the main
845 register files; the unmodified blocks are still accessed at their
846 normal location (the shadow files are not a complete copy of the
847 register files - they only contain those parts that have actually been
848 modified). If the commit process is interrupted at any point during the
849 commit process, the server processes will continue to access the
850 shadow files until you can repeat the commit procedure and complete
851 the writing of data to the main register files. You can perform
852 multiple update operations to the registers before you commit the
853 changes to the system files, or you can execute the commit operation
854 at the end of each update operation. When the commit phase has
855 completed successfully, any running server processes are instructed to
856 switch their operations to the new, operational register, and the
857 temporary shadow files are deleted.
862 <sect2 id="shadow-registers-how-to-use">
863 <title>How to Use Shadow Register Files</title>
866 The first step is to allocate space on your system for the shadow
868 You do this by adding a <literal>shadow</literal> entry to the
869 <literal>zebra.cfg</literal> file.
870 The syntax of the <literal>shadow</literal> entry is exactly the
871 same as for the <literal>register</literal> entry
872 (see <xref linkend="register-location"/>).
873 The location of the shadow area should be
874 <emphasis>different</emphasis> from the location of the main register
875 area (if you have specified one - remember that if you provide no
876 <literal>register</literal> setting, the default register area is the
877 working directory of the server and indexing processes).
881 The following excerpt from a <literal>zebra.cfg</literal> file shows
882 one example of a setup that configures both the main register
883 location and the shadow file area.
884 Note that two directories or partitions have been set aside
885 for the shadow file area. You can specify any number of directories
886 for each of the file areas, but remember that there should be no
887 overlaps between the directories used for the main registers and the
888 shadow files, respectively.
894 shadow: /scratch1:100M /scratch2:200M
900 When shadow files are enabled, an extra command is available at the
901 <literal>zebraidx</literal> command line.
902 In order to make changes to the system take effect for the
903 users, you'll have to submit a "commit" command after a
904 (sequence of) update operation(s).
910 $ zebraidx update /d1/records
917 Or you can execute multiple updates before committing the changes:
923 $ zebraidx -g books update /d1/records /d2/more-records
924 $ zebraidx -g fun update /d3/fun-records
931 If one of the update operations above had been interrupted, the commit
932 operation on the last line would fail: <literal>zebraidx</literal>
933 will not let you commit changes that would destroy the running register.
934 You'll have to rerun all of the update operations since your last
935 commit operation, before you can commit the new changes.
939 Similarly, if the commit operation fails, <literal>zebraidx</literal>
940 will not let you start a new update operation before you have
941 successfully repeated the commit operation.
942 The server processes will keep accessing the shadow files rather
943 than the (possibly damaged) blocks of the main register files
944 until the commit operation has successfully completed.
948 You should be aware that update operations may take slightly longer
949 when the shadow register system is enabled, since more file access
950 operations are involved. Further, while the disk space required for
951 the shadow register data is modest for a small update operation, you
952 may prefer to disable the system if you are adding a very large number
953 of records to an already very large database (we use the terms
954 <emphasis>large</emphasis> and <emphasis>modest</emphasis>
955 very loosely here, since every application will have a
956 different perception of size).
957 To update the system without the use of the the shadow files,
958 simply run <literal>zebraidx</literal> with the <literal>-n</literal>
959 option (note that you do not have to execute the
960 <emphasis>commit</emphasis> command of <literal>zebraidx</literal>
961 when you temporarily disable the use of the shadow registers in
963 Note also that, just as when the shadow registers are not enabled,
964 server processes will be barred from accessing the main register
965 while the update procedure takes place.
973 <sect1 id="administration-ranking">
974 <title>Relevance Ranking and Sorting of Result Sets</title>
976 <sect2 id="administration-overview">
977 <title>Overview</title>
979 The default ordering of a result set is left up to the server,
980 which inside Zebra means sorting in ascending document ID order.
981 This is not always the order humans want to browse the sometimes
982 quite large hit sets. Ranking and sorting comes to the rescue.
986 In cases where a good presentation ordering can be computed at
987 indexing time, we can use a fixed <literal>static ranking</literal>
988 scheme, which is provided for the <literal>alvis</literal>
989 indexing filter. This defines a fixed ordering of hit lists,
990 independently of the query issued.
994 There are cases, however, where relevance of hit set documents is
995 highly dependent on the query processed.
996 Simply put, <literal>dynamic relevance ranking</literal>
997 sorts a set of retrieved records such that those most likely to be
998 relevant to your request are retrieved first.
999 Internally, Zebra retrieves all documents that satisfy your
1000 query, and re-orders the hit list to arrange them based on
1001 a measurement of similarity between your query and the content of
1006 Finally, there are situations where hit sets of documents should be
1007 <literal>sorted</literal> during query time according to the
1008 lexicographical ordering of certain sort indexes created at
1014 <sect2 id="administration-ranking-static">
1015 <title>Static Ranking</title>
1018 Zebra uses internally inverted indexes to look up term occurencies
1019 in documents. Multiple queries from different indexes can be
1020 combined by the binary boolean operations <literal>AND</literal>,
1021 <literal>OR</literal> and/or <literal>NOT</literal> (which
1022 is in fact a binary <literal>AND NOT</literal> operation).
1023 To ensure fast query execution
1024 speed, all indexes have to be sorted in the same order.
1027 The indexes are normally sorted according to document
1028 <literal>ID</literal> in
1029 ascending order, and any query which does not invoke a special
1030 re-ranking function will therefore retrieve the result set in
1032 <literal>ID</literal>
1040 directive in the main core Zebra configuration file, the internal document
1041 keys used for ordering are augmented by a preceding integer, which
1042 contains the static rank of a given document, and the index lists
1044 first by ascending static rank,
1045 then by ascending document <literal>ID</literal>.
1047 is the ``best'' rank, as it occurs at the
1048 beginning of the list; higher numbers represent worse scores.
1051 The experimental <literal>alvis</literal> filter provides a
1052 directive to fetch static rank information out of the indexed XML
1053 records, thus making <emphasis>all</emphasis> hit sets ordered
1054 after <emphasis>ascending</emphasis> static
1055 rank, and for those doc's which have the same static rank, ordered
1056 after <emphasis>ascending</emphasis> doc <literal>ID</literal>.
1057 See <xref linkend="record-model-alvisxslt"/> for the gory details.
1062 <sect2 id="administration-ranking-dynamic">
1063 <title>Dynamic Ranking</title>
1065 In order to fiddle with the static rank order, it is necessary to
1066 invoke additional re-ranking/re-ordering using dynamic
1067 ranking or score functions. These functions return positive
1068 integer scores, where <emphasis>highest</emphasis> score is
1070 hit sets are sorted according to <emphasis>descending</emphasis>
1072 to the index lists which are sorted according to
1073 ascending rank number and document ID).
1076 Dynamic ranking is enabled by a directive like one of the
1077 following in the zebra configuration file (use only one of these a time!):
1079 rank: rank-1 # default TDF-IDF like
1080 rank: rank-static # dummy do-nothing
1085 Dynamic ranking is done at query time rather than
1086 indexing time (this is why we
1087 call it ``dynamic ranking'' in the first place ...)
1088 It is invoked by adding
1089 the Bib-1 relation attribute with
1090 value ``relevance'' to the PQF query (that is,
1091 <literal>@attr 2=102</literal>, see also
1092 <ulink url="&url.z39.50;bib1.html">
1093 The BIB-1 Attribute Set Semantics</ulink>, also in
1094 <ulink url="&url.z39.50.attset.bib1;">HTML</ulink>).
1095 To find all articles with the word <literal>Eoraptor</literal> in
1096 the title, and present them relevance ranked, issue the PQF query:
1098 @attr 2=102 @attr 1=4 Eoraptor
1102 <sect3 id="administration-ranking-dynamic-rank1">
1103 <title>Dynamically ranking using PQF queries with the 'rank-1'
1107 The default <literal>rank-1</literal> ranking module implements a
1108 TF/IDF (Term Frequecy over Inverse Document Frequency) like
1109 algorithm. In contrast to the usual defintion of TF/IDF
1110 algorithms, which only considers searching in one full-text
1111 index, this one works on multiple indexes at the same time.
1113 Zebra does boolean queries and searches in specific addressed
1114 indexes (there are inverted indexes pointing from terms in the
1115 dictionary to documents and term positions inside documents).
1119 <term>Query Components</term>
1122 First, the boolean query is dismantled into it's principal components,
1123 i.e. atomic queries where one term is looked up in one index.
1124 For example, the query
1126 @attr 2=102 @and @attr 1=1010 Utah @attr 1=1018 Springer
1128 is a boolean AND between the atomic parts
1130 @attr 2=102 @attr 1=1010 Utah
1134 @attr 2=102 @attr 1=1018 Springer
1136 which gets processed each for itself.
1142 <term>Atomic hit lists</term>
1145 Second, for each atomic query, the hit list of documents is
1149 In this example, two hit lists for each index
1150 <literal>@attr 1=1010</literal> and
1151 <literal>@attr 1=1018</literal> are computed.
1157 <term>Atomic scores</term>
1160 Third, each document in the hit list is assigned a score (_if_ ranking
1161 is enabled and requested in the query) using a TF/IDF scheme.
1164 In this example, both atomic parts of the query assign the magic
1165 <literal>@attr 2=102</literal> relevance attribute, and are
1166 to be used in the relevance ranking functions.
1169 It is possible to apply dynamic ranking on only parts of the
1172 @and @attr 2=102 @attr 1=1010 Utah @attr 1=1018 Springer
1174 searches for all documents which have the term 'Utah' on the
1175 body of text, and which have the term 'Springer' in the publisher
1176 field, and sort them in the order of the relevance ranking made on
1177 the body-of-text index only.
1183 <term>Hit list merging</term>
1186 Fourth, the atomic hit lists are merged according to the boolean
1187 conditions to a final hit list of documents to be returned.
1190 This step is always performed, independently of the fact that
1191 dynamic ranking is enabled or not.
1197 <term>Document score computation</term>
1200 Fifth, the total score of a document is computed as a linear
1201 combination of the atomic scores of the atomic hit lists
1204 Ranking weights may be used to pass a value to a ranking
1205 algorithm, using the non-standard BIB-1 attribute type 9.
1206 This allows one branch of a query to use one value while
1207 another branch uses a different one. For example, we can search
1208 for <literal>utah</literal> in the
1209 <literal>@attr 1=4</literal> index with weight 30, as
1210 well as in the <literal>@attr 1=1010</literal> index with weight 20:
1212 @attr 2=102 @or @attr 9=30 @attr 1=4 utah @attr 9=20 @attr 1=1010 city
1216 The default weight is
1217 sqrt(1000) ~ 34 , as the Z39.50 standard prescribes that the top score
1218 is 1000 and the bottom score is 0, encoded in integers.
1222 The ranking-weight feature is experimental. It may change in future
1230 <term>Re-sorting of hit list</term>
1233 Finally, the final hit list is re-ordered according to scores.
1241 Still need to describe the exact TF/IDF formula. Here's the info, need -->
1242 <!--to extract it in human readable form .. MC
1244 static int calc (void *set_handle, zint sysno, zint staticrank,
1247 int i, lo, divisor, score = 0;
1248 struct rank_set_info *si = (struct rank_set_info *) set_handle;
1250 if (!si->no_rank_entries)
1251 return -1; /* ranking not enabled for any terms */
1253 for (i = 0; i < si->no_entries; i++)
1255 yaz_log(log_level, "calc: i=%d rank_flag=%d lo=%d",
1256 i, si->entries[i].rank_flag, si->entries[i].local_occur);
1257 if (si->entries[i].rank_flag && (lo = si->entries[i].local_occur))
1258 score += (8+log2_int (lo)) * si->entries[i].global_inv *
1259 si->entries[i].rank_weight;
1261 divisor = si->no_rank_entries * (8+log2_int (si->last_pos/si->no_entries));
1262 score = score / divisor;
1263 yaz_log(log_level, "calc sysno=" ZINT_FORMAT " score=%d", sysno, score);
1266 /* reset the counts for the next term */
1267 for (i = 0; i < si->no_entries; i++)
1268 si->entries[i].local_occur = 0;
1273 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
1274 si->entries[i].rank_weight is the weight assigner per index (default 34, or set in the @attr 9=xyz magic)
1276 Finally, the IDF part is computed as:
1278 static void *begin (struct zebra_register *reg,
1279 void *class_handle, RSET rset, NMEM nmem,
1280 TERMID *terms, int numterms)
1282 struct rank_set_info *si =
1283 (struct rank_set_info *) nmem_malloc (nmem,sizeof(*si));
1286 yaz_log(log_level, "rank-1 begin");
1287 si->no_entries = numterms;
1288 si->no_rank_entries = 0;
1290 si->entries = (struct rank_term_info *)
1291 nmem_malloc (si->nmem, sizeof(*si->entries)*numterms);
1292 for (i = 0; i < numterms; i++)
1294 zint g = rset_count(terms[i]->rset);
1295 yaz_log(log_level, "i=%d flags=%s '%s'", i,
1296 terms[i]->flags, terms[i]->name );
1297 if (!strncmp (terms[i]->flags, "rank,", 5))
1299 const char *cp = strstr(terms[i]->flags+4, ",w=");
1300 si->entries[i].rank_flag = 1;
1302 si->entries[i].rank_weight = atoi (cp+3);
1304 si->entries[i].rank_weight = 34; /* sqrroot of 1000 */
1305 yaz_log(log_level, " i=%d weight=%d g="ZINT_FORMAT, i,
1306 si->entries[i].rank_weight, g);
1307 (si->no_rank_entries)++;
1310 si->entries[i].rank_flag = 0;
1311 si->entries[i].local_occur = 0; /* FIXME */
1312 si->entries[i].global_occur = g;
1313 si->entries[i].global_inv = 32 - log2_int (g);
1314 yaz_log(log_level, " global_inv = %d g = " ZINT_FORMAT,
1315 (int) (32-log2_int (g)), g);
1316 si->entries[i].term = terms[i];
1317 si->entries[i].term_index=i;
1318 terms[i]->rankpriv = &(si->entries[i]);
1324 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
1326 si->entries[i].global_inv = 32 - log2_int (g);
1333 The <literal>rank-1</literal> algorithm
1334 does not use the static rank
1335 information in the list keys, and will produce the same ordering
1336 with or without static ranking enabled.
1341 <sect3 id="administration-ranking-dynamic-rank1">
1342 <title>Dynamically ranking PQF queries with the 'rank-static'
1345 The dummy <literal>rank-static</literal> reranking/scoring
1346 function returns just
1347 <literal>score = max int - staticrank</literal>
1348 in order to preserve the static ordering of hit sets that would
1349 have been produced had it not been invoked.
1350 Obviously, to combine static and dynamic ranking usefully,
1352 to make a new ranking
1353 function; this is left
1354 as an exercise for the reader.
1361 <literal>Dynamic ranking</literal> is not compatible
1362 with <literal>estimated hit sizes</literal>, as all documents in
1363 a hit set must be accessed to compute the correct placing in a
1364 ranking sorted list. Therefore the use attribute setting
1365 <literal>@attr 2=102</literal> clashes with
1366 <literal>@attr 9=integer</literal>.
1371 we might want to add ranking like this:
1373 Simple BM25 Extension to Multiple Weighted Fields
1374 Stephen Robertson, Hugo Zaragoza and Michael Taylor
1378 mitaylor2microsoft.com
1383 <sect3 id="administration-ranking-dynamic-cql">
1384 <title>Dynamically ranking CQL queries</title>
1386 Dynamic ranking can be enabled during sever side CQL
1387 query expansion by adding <literal>@attr 2=102</literal>
1388 chunks to the CQL config file. For example
1390 relationModifier.relevant = 2=102
1392 invokes dynamic ranking each time a CQL query of the form
1395 Z> f alvis.text =/relevant house
1397 is issued. Dynamic ranking can also be automatically used on
1398 specific CQL indexes by (for example) setting
1400 index.alvis.text = 1=text 2=102
1402 which then invokes dynamic ranking each time a CQL query of the form
1405 Z> f alvis.text = house
1415 <sect2 id="administration-ranking-sorting">
1416 <title>Sorting</title>
1418 Zebra sorts efficiently using special sorting indexes
1419 (type=<literal>s</literal>; so each sortable index must be known
1420 at indexing time, specified in the configuration of record
1421 indexing. For example, to enable sorting according to the BIB-1
1422 <literal>Date/time-added-to-db</literal> field, one could add the line
1424 xelm /*/@created Date/time-added-to-db:s
1426 to any <literal>.abs</literal> record-indexing configuration file.
1427 Similarly, one could add an indexing element of the form
1429 <z:index name="date-modified" type="s">
1430 <xsl:value-of select="some/xpath"/>
1433 to any <literal>alvis</literal>-filter indexing stylesheet.
1436 Indexing can be specified at searching time using a query term
1437 carrying the non-standard
1438 BIB-1 attribute-type <literal>7</literal>. This removes the
1439 need to send a Z39.50 <literal>Sort Request</literal>
1440 separately, and can dramatically improve latency when the client
1441 and server are on separate networks.
1442 The sorting part of the query is separate from the rest of the
1443 query - the actual search specification - and must be combined
1447 A sorting subquery needs two attributes: an index (such as a
1448 BIB-1 type-1 attribute) specifying which index to sort on, and a
1449 type-7 attribute whose value is be <literal>1</literal> for
1450 ascending sorting, or <literal>2</literal> for descending. The
1451 term associated with the sorting attribute is the priority of
1452 the sort key, where <literal>0</literal> specifies the primary
1453 sort key, <literal>1</literal> the secondary sort key, and so
1456 <para>For example, a search for water, sort by title (ascending),
1457 is expressed by the PQF query
1459 @or @attr 1=1016 water @attr 7=1 @attr 1=4 0
1461 whereas a search for water, sort by title ascending,
1462 then date descending would be
1464 @or @or @attr 1=1016 water @attr 7=1 @attr 1=4 0 @attr 7=2 @attr 1=30 1
1468 Notice the fundamental differences between <literal>dynamic
1469 ranking</literal> and <literal>sorting</literal>: there can be
1470 only one ranking function defined and configured; but multiple
1471 sorting indexes can be specified dynamically at search
1472 time. Ranking does not need to use specific indexes, so
1473 dynamic ranking can be enabled and disabled without
1474 re-indexing; whereas, sorting indexes need to be
1475 defined before indexing.
1483 <sect1 id="administration-extended-services">
1484 <title>Extended Services: Remote Insert, Update and Delete</title>
1488 Extended services are only supported when accessing the Zebra
1489 server using the <ulink url="&url.z39.50;">Z39.50</ulink>
1490 protocol. The <ulink url="&url.sru;">SRU</ulink> protocol does
1491 not support extended services.
1496 The extended services are not enabled by default in zebra - due to the
1497 fact that they modify the system. Zebra can be configured
1499 search, and to allow only updates for a particular admin user
1500 in the main zebra configuration file <filename>zebra.cfg</filename>.
1501 For user <literal>admin</literal>, you could use:
1505 passwd: passwordfile
1507 And in the password file
1508 <filename>passwordfile</filename>, you have to specify users and
1509 encrypted passwords as colon separated strings.
1510 Use a tool like <filename>htpasswd</filename>
1511 to maintain the encrypted passwords.
1515 It is essential to configure Zebra to store records internally,
1517 modifications and deletion of records:
1522 The general record type should be set to any record filter which
1523 is able to parse XML records, you may use any of the two
1524 declarations (but not both simultaneously!)
1527 # recordType: alvis.filter_alvis_config.xml
1529 To enable transaction safe shadow indexing,
1530 which is extra important for this kind of operation, set
1532 shadow: directoryname: size (e.g. 1000M)
1537 It is not possible to carry information about record types or
1538 similar to Zebra when using extended services, due to
1539 limitations of the <ulink url="&url.z39.50;">Z39.50</ulink>
1540 protocol. Therefore, indexing filters can not be chosen on a
1541 per-record basis. One and only one general XML indexing filter
1543 <!-- but because it is represented as an OID, we would need some
1544 form of proprietary mapping scheme between record type strings and
1547 However, as a minimum, it would be extremely useful to enable
1548 people to use MARC21, assuming grs.marcxml.marc21 as a record
1555 <sect2 id="administration-extended-services-z3950">
1556 <title>Extended services in the Z39.50 protocol</title>
1559 The <ulink url="&url.z39.50;">Z39.50</ulink> standard allows
1560 servers to accept special binary <emphasis>extended services</emphasis>
1561 protocol packages, which may be used to insert, update and delete
1562 records into servers. These carry control and update
1563 information to the servers, which are encoded in seven package fields:
1566 <table id="administration-extended-services-z3950-table" frame="top">
1567 <title>Extended services Z39.50 Package Fields</title>
1571 <entry>Parameter</entry>
1572 <entry>Value</entry>
1573 <entry>Notes</entry>
1578 <entry><literal>type</literal></entry>
1579 <entry><literal>'update'</literal></entry>
1580 <entry>Must be set to trigger extended services</entry>
1583 <entry><literal>action</literal></entry>
1584 <entry><literal>string</literal></entry>
1586 Extended service action type with
1587 one of four possible values: <literal>recordInsert</literal>,
1588 <literal>recordReplace</literal>,
1589 <literal>recordDelete</literal>,
1590 and <literal>specialUpdate</literal>
1594 <entry><literal>record</literal></entry>
1595 <entry><literal>XML string</literal></entry>
1596 <entry>An XML formatted string containing the record</entry>
1599 <entry><literal>syntax</literal></entry>
1600 <entry><literal>'xml'</literal></entry>
1601 <entry>Only XML record syntax is supported</entry>
1604 <entry><literal>recordIdOpaque</literal></entry>
1605 <entry><literal>string</literal></entry>
1607 Optional client-supplied, opaque record
1608 identifier used under insert operations.
1612 <entry><literal>recordIdNumber </literal></entry>
1613 <entry><literal>positive number</literal></entry>
1614 <entry>Zebra's internal system number, only for update
1619 <entry><literal>databaseName</literal></entry>
1620 <entry><literal>database identifier</literal></entry>
1622 The name of the database to which the extended services should be
1632 The <literal>action</literal> parameter can be any of
1633 <literal>recordInsert</literal> (will fail if the record already exists),
1634 <literal>recordReplace</literal> (will fail if the record does not exist),
1635 <literal>recordDelete</literal> (will fail if the record does not
1637 <literal>specialUpdate</literal> (will insert or update the record
1642 During a <literal>recordInsert</literal> action, the
1643 usual rules for internal record ID generation apply, unless an
1644 optional <literal>recordIdNumber</literal> Zebra internal ID or a
1645 <literal>recordIdOpaque</literal> string identifier is assigned.
1646 The default ID generation is
1647 configured using the <literal>recordId:</literal> from
1648 <filename>zebra.cfg</filename>.
1652 The actions <literal>recordReplace</literal> or
1653 <literal>recordDelete</literal> need specification of the additional
1654 <literal>recordIdNumber</literal> parameter, which must be an
1655 existing Zebra internal system ID number, or the optional
1656 <literal>recordIdOpaque</literal> string parameter.
1660 When retrieving existing
1661 records indexed with GRS indexing filters, the Zebra internal
1662 ID number is returned in the field
1663 <literal>/*/id:idzebra/localnumber</literal> in the namespace
1664 <literal>xmlns:id="http://www.indexdata.dk/zebra/"</literal>,
1665 where it can be picked up for later record updates or deletes.
1668 Records indexed with the <literal>alvis</literal> filter
1669 have similar means to discover the internal Zebra ID.
1673 The <literal>recordIdOpaque</literal> string parameter
1674 is an client-supplied, opaque record
1675 identifier, which may be used under
1676 insert, update and delete operations. The
1677 client software is responsible for assigning these to
1678 records. This identifier will
1679 replace zebra's own automagic identifier generation with a unique
1680 mapping from <literal>recordIdOpaque</literal> to the
1681 Zebra internal <literal>recordIdNumber</literal>.
1682 <emphasis>The opaque <literal>recordIdOpaque</literal> string
1684 are not visible in retrieval records, nor are
1685 searchable, so the value of this parameter is
1686 questionable. It serves mostly as a convenient mapping from
1687 application domain string identifiers to Zebra internal ID's.
1693 <sect2 id="administration-extended-services-yaz-client">
1694 <title>Extended services from yaz-client</title>
1697 We can now start a yaz-client admin session and create a database:
1700 $ yaz-client localhost:9999 -u admin/secret
1704 Now the <literal>Default</literal> database was created,
1705 we can insert an XML file (esdd0006.grs
1706 from example/gils/records) and index it:
1709 Z> update insert id1234 esdd0006.grs
1712 The 3rd parameter - <literal>id1234</literal> here -
1713 is the <literal>recordIdOpaque</literal> package field.
1716 Actually, we should have a way to specify "no opaque record id" for
1717 yaz-client's update command.. We'll fix that.
1720 The newly inserted record can be searched as usual:
1725 Received SearchResponse.
1726 Search was a success.
1727 Number of hits: 1, setno 1
1728 SearchResult-1: term=utah cnt=1
1735 Let's delete the beast, using the same
1736 <literal>recordIdOpaque</literal> string parameter:
1739 Z> update delete id1234
1740 No last record (update ignored)
1741 Z> update delete 1 esdd0006.grs
1742 Got extended services response
1747 Received SearchResponse.
1748 Search was a success.
1749 Number of hits: 0, setno 2
1750 SearchResult-1: term=utah cnt=0
1757 If shadow register is enabled in your
1758 <filename>zebra.cfg</filename>,
1759 you must run the adm-commit command
1765 after each update session in order write your changes from the
1766 shadow to the life register space.
1771 <sect2 id="administration-extended-services-yaz-php">
1772 <title>Extended services from yaz-php</title>
1775 Extended services are also available from the YAZ PHP client layer. An
1776 example of an YAZ-PHP extended service transaction is given here:
1779 $record = '<record><title>A fine specimen of a record</title></record>';
1781 $options = array('action' => 'recordInsert',
1783 'record' => $record,
1784 'databaseName' => 'mydatabase'
1787 yaz_es($yaz, 'update', $options);
1788 yaz_es($yaz, 'commit', array());
1791 if ($error = yaz_error($yaz))
1801 <!-- Keep this comment at the end of the file
1806 sgml-minimize-attributes:nil
1807 sgml-always-quote-attributes:t
1810 sgml-parent-document: "zebra.xml"
1811 sgml-local-catalogs: nil
1812 sgml-namecase-general:t