Define oslash; so that our address looks OK
[idzebra-moved-to-github.git] / doc / examples.xml
1 <chapter id="examples">
2  <!-- $Id: examples.xml,v 1.15 2002-10-30 14:45:42 adam Exp $ -->
3  <title>Example Configurations</title>
4
5  <sect1>
6   <title>Overview</title>
7
8   <para>
9    <literal>zebraidx</literal> and <literal>zebrasrv</literal> are both
10    driven by a master configuration file, which may refer to other
11    subsidiary configuration files.  By default, they try to use
12    <filename>zebra.cfg</filename> in the working directory as the
13    master file; but this can be changed using the <literal>-c</literal>
14    option to specify an alternative master configuration file.
15   </para>
16   <para>
17    The master configuration file tells Zebra:
18    <itemizedlist>
19
20     <listitem>
21      <para>
22       Where to find subsidiary configuration files, including
23       <literal>default.idx</literal>
24       which specifies the default indexing rules.
25      </para>
26     </listitem>
27
28     <listitem>
29      <para>
30       What attribute sets to recognise in searches.
31      </para>
32     </listitem>
33
34     <listitem>
35      <para>
36       Policy details such as what record type to expect, what
37       low-level indexing algorithm to use, how to identify potential
38       duplicate records, etc.
39      </para>
40     </listitem>
41
42    </itemizedlist>
43   </para>
44   <para>
45    Now let's see what goes in the <literal>zebra.cfg</literal> file
46    for some example configurations.
47   </para>
48  </sect1>
49
50  <sect1 id="example1">
51   <title>Example 1: XML Indexing And Searching</title>
52
53   <para>
54    This example shows how Zebra can be used with absolutely minimal
55    configuration to index a body of
56    <ulink url="http://www.w3.org/xml/###">XML</ulink>
57    documents, and search them using
58    <ulink url="http://www.w3.org/xpath/###">XPath</ulink>
59    expressions to specify access points.
60   </para>
61   <para>
62    Go to the <literal>examples/dinosauricon</literal> subdirectory
63    of the distribution archive.
64    There you will find a <literal>records</literal> subdirectory,
65    which contains some raw XML data to be added to the database: in
66    this case, as single file, <literal>genera.xml</literal>,
67    which contain information about all the known dinosaur genera as of
68    August 2002.
69   </para>
70   <para>
71    Now we need to create the Zebra database, which we do with the
72    Zebra indexer, <literal>zebraidx</literal>, which is
73    driven by the <literal>zebra.cfg</literal> configuration file.
74    For our purposes, we don't need any
75    special behaviour - we can use the defaults - so we start with a
76    minimal file that just tells <literal>zebraidx</literal> where to
77    find the default indexing rules, and how to parse the records:
78    <screen>
79     profilePath: .:../../tab
80     recordType: grs.sgml
81    </screen>
82   </para>
83   <para>
84    That's all you need for a minimal Zebra configuration.  Now you can
85    roll the XML records into the database and build the indexes:
86    <screen>
87     zebraidx update records
88    </screen>
89   </para>
90   <para>
91    Now start the server.  Like the indexer, its behaviour is
92    controlled by the
93    <literal>zebra.cfg</literal> file; and like the indexer, it works
94    just fine with this minimal configuration.
95    <screen>
96         zebrasrv
97    </screen>
98    By default, the server listens on IP port number 9999, although
99    this can easily be changed - see 
100    <xref linkend="zebrasrv"/>.
101   </para>
102   <para>
103    Now you can use the Z39.50 client program of your choice to execute
104    XPath-based boolean queries and fetch the XML records that satisfy
105    them:
106    <screen>
107     $ yaz-client tcp:@:9999
108     Connecting...Ok.
109     Z&gt; find @attr 1=/GENUS/SPECIES/AUTHOR/@name Wedel
110     Number of hits: 1
111     Z&gt; format xml
112     Z&gt; show 1
113     &lt;GENUS name="Sauroposeidon" type="with"&gt;
114      &lt;MEANING&gt;lizard Poseidon &lt;LOW&gt;(Greek god of, among other things, earthquakes)&lt;/LOW&gt;&lt;/MEANING&gt;
115      &lt;SPECIES name="proteles"&gt;
116       &lt;AUTHOR type="vide" name="Franklin" year="2000"&gt;&lt;/AUTHOR&gt;
117       &lt;AUTHOR name="Wedel, Cifelli, Sanders"&gt;&lt;/AUTHOR&gt;
118      &lt;/SPECIES&gt;
119      &lt;PLACE name="Oklahoma"&gt;&lt;/PLACE&gt;
120      &lt;TIME value="Albian"&gt;&lt;/TIME&gt;
121      &lt;LENGTH value="30" q="1"&gt;&lt;/LENGTH&gt;
122      &lt;REMAINS content="rib, cervical vertebrae"&gt;&lt;/REMAINS&gt;
123      &lt;ESSAY&gt;
124       &lt;P&gt; This new &lt;NOMEN name="Brachiosaurus"&gt;&lt;/NOMEN&gt;-like &lt;LINK content="dinosaur"&gt;&lt;/LINK&gt;
125       was perhaps the tallest. With its head raised, it stood 60 feet (nearly
126       20 m) tall. &lt;/P&gt;
127      &lt;/ESSAY&gt;
128       &lt;idzebra xmlns="http://www.indexdata.dk/zebra/"&gt;
129         &lt;size&gt;593&lt;/size&gt;
130         &lt;localnumber&gt;891&lt;/localnumber&gt;
131         &lt;filename&gt;records/genera.xml&lt;/filename&gt;
132      &lt;/idzebra&gt;
133     &lt;/GENUS&gt;
134    </screen>
135   </para>
136   <para>
137    Now wasn't that easy?
138   </para>
139  </sect1>
140
141
142  <sect1 id="example2">
143   <title>Example 2: Supporting Interoperable Searches</title>
144
145   <para>
146    The problem with the previous example is that you need to know the
147    structure of the documents in order to find them.  For example,
148    when we wanted to know the genera for which Matt Wedel is an
149    author
150    (<foreignphrase role="taxon">Sauroposeidon proteles</foreignphrase>),
151    we had to formulate a complex XPath 
152    <literal>1=/GENUS/SPECIES/AUTHOR/@name</literal>
153    which embodies the knowledge that author names are specified in the
154    <literal>name</literal> attribute of the
155    <literal>&lt;AUTHOR&gt;</literal> element,
156    which is inside the
157    <literal>&lt;SPECIES&gt;</literal> element,
158    which in turn is inside the top-level
159    <literal>&lt;GENUS&gt;</literal> element.
160   </para>
161   <para>
162    This is bad not just because it requires a lot of typing, but more
163    significantly because it ties searching semantics to the physical
164    structure of the searched records.  You can't use the same search
165    specification to search two databases if their internal
166    representations are different.  Consider an alternative dinosaur
167    database in which the records have author names specified
168    inside an <literal>&lt;authorName&gt;</literal> element directly
169    inside a top-level <literal>&lt;taxon&gt;</literal> element: then
170    you'd need to search for them using
171    <literal>1=/taxon/authorName</literal>
172   </para>
173   <para>
174    How, then, can we build broadcasting Information Retrieval
175    applications that look for records in many different databases?
176    The Z39.50 protocol offers a powerful and general solution to this:
177    abstract ``access points''.  In the Z39.50 model, an access point
178    is simply a point at which searches can be directed.  Nothing is
179    said about implementation: in a given database, an access point
180    might be implemented as an index, a path into physical records, an
181    algorithm for interrogating relational tables or whatever works.
182    The key point is that the semantics of an access point are fixed
183    and well defined.
184   </para>
185   <para>
186    For convenience, access points are gathered into <firstterm>attribute
187    sets</firstterm>.  For example, the BIB-1 attribute set is supposed to
188    contain bibliographic access points such as author, title, subject
189    and ISBN; the GEO attribute set contains access points pertaining
190    to geospatial information (bounding box, ###, etc.); the CIMI
191    attribute set contains access points to do with museum collections
192    (provenance, inscriptions, etc.)
193   </para>
194   <para>
195    In practice, the BIB-1 attribute set has tended to be a dumping
196    ground for all sorts of access points, so that, for example, it
197    includes some geospatial access points as well as strictly
198    bibliographic ones.  Nevertheless, the key point is that this model
199    allows a layer of abstraction over the physical representation of
200    records in databases.
201   </para>
202   <para>
203    In the BIB-1 attribute set, an author search is represented by
204    access point 1003.  (See
205    <ulink url="###bib1-semantics"/>)
206    So we need to configure our dinosaur database so that searches for
207    BIB-1 access point 1003 look the 
208    <literal>name</literal> attribute of the
209    <literal>&lt;AUTHOR&gt;</literal> element,
210    inside the
211    <literal>&lt;SPECIES&gt;</literal> element,
212    inside the top-level
213    <literal>&lt;GENUS&gt;</literal> element.
214   </para>
215   <para>
216    This is a two-step process.  First, we need to tell Zebra that we
217    want to support the BIB-1 attribute set.  Then we need to tell it
218    which elements of its record pertain to access point 1003.
219   </para>
220   <para>
221    We need to create an <link linkend="abs-file">Abstract Syntax
222    file</link> named after the document element of the records we're
223    working with, plus a <literal>.abs</literal> suffix - in this case,
224    <literal>GENUS.abs</literal> - as follows:
225   </para>
226   <itemizedlist>
227    <listitem>
228     <para>
229      
230     </para>
231    </listitem>
232    <listitem>
233     <para>
234     </para>
235    </listitem>
236   </itemizedlist>
237  </sect1>
238 </chapter>
239
240
241 <!--
242         The simplest hello-world example could go like this:
243         
244         Index the document
245         
246         <book>
247            <title>The art of motorcycle maintenance</title>
248            <subject scheme="Dewey">zen</subject>
249         </book>
250         
251         And search it like
252         
253         f @attr 1=/book/title motorcycle
254         
255         f @attr 1=/book/subject[@scheme=Dewey] zen
256         
257         If you suddenly decide you want broader interop, you can add
258         an abs file (more or less like this):
259         
260         attset bib1.att
261         tagset tagsetg.tag
262         
263         elm (2,1)       title   title
264         elm (2,21)      subject  subject
265 -->
266
267 <!--
268 How to include images:
269
270         <mediaobject>
271           <imageobject>
272             <imagedata fileref="system.eps" format="eps">
273           </imageobject>
274           <imageobject>
275             <imagedata fileref="system.gif" format="gif">
276           </imageobject>
277           <textobject>
278             <phrase>The Multi-Lingual Search System Architecture</phrase>
279           </textobject>
280           <caption>
281             <para>
282               <emphasis role="strong">
283                 The Multi-Lingual Search System Architecture.
284               </emphasis>
285               <para>
286                 Network connections across local area networks are
287                 represented by straight lines, and those over the
288                 internet by jagged lines.
289           </caption>
290         </mediaobject>
291
292 Where the three <*object> thingies inside the top-level <mediaobject>
293 are decreasingly preferred version to include depending on what the
294 rendering engine can handle.  I generated the EPS version of the image
295 by exporting a line-drawing done in TGIF, then converted that to the
296 GIF using a shell-script called "epstogif" which used an appallingly
297 baroque sequence of conversions, which I would prefer not to pollute
298 the Zebra build environment with:
299
300         #!/bin/sh
301
302         # Yes, what follows is stupidly convoluted, but I can't find a
303         # more straightforward path from the EPS generated by tgif's
304         # "Print" command into a browser-friendly format.
305
306         file=`echo "$1" | sed 's/\.eps//'`
307         ps2pdf "$1" "$file".pdf
308         pdftopbm "$file".pdf "$file"
309         pnmscale 0.50 < "$file"-000001.pbm | pnmcrop | ppmtogif
310         rm -f "$file".pdf "$file"-000001.pbm
311
312 -->
313
314  <!-- Keep this comment at the end of the file
315  Local variables:
316  mode: sgml
317  sgml-omittag:t
318  sgml-shorttag:t
319  sgml-minimize-attributes:nil
320  sgml-always-quote-attributes:t
321  sgml-indent-step:1
322  sgml-indent-data:t
323  sgml-parent-document: "zebra.xml"
324  sgml-local-catalogs: nil
325  sgml-namecase-general:t
326  End:
327  -->