This example shows how Zebra can be used with absolutely minimal configuration to index a body of XML documents, and search them using XPath expressions to specify access points.
Go to the zebra/examples/dinosauricon directory. There you will find a records subdirectory, which contains some raw XML data to be added to the database: in this case, two files, genera.xml and taxa.xml, which contain information about all the known dinosaur genera as of August 2002.
Now we need to create the Zebra database, which we do with the Zebra indexer, zebraidx. This program's behaviour is driven by a configuration life, generally called zebra.cfg, although this can be changed with the -c option. For our purposes, we don't need any special behaviour - we can use the defaults - so an empty configuration will do just fine. We can either create an empty zebra.cfg or specify the name of an existing empty file using, for example, -c /dev/null.
In this case, we'll use an empty zebra.cfg so we can add more configuration to it later.
That's all you need for a minimal Zebra configuration. Now you can roll the XML records into the database and build the indexes:
zebraidx -t grs.sgml update records |
Now start the server. Like the indexer, its behaviour is controlled by a configuration file, generally zebra.cfg; and like the indexer, it works just fine with an empty configuration.
zebrasrv |
Now you can use the Z39.50 client program of your choice to execute XPath-based boolean queries and fetch the XML records that satisfy them:
Z> open tcp:@:9999 Connecting...Ok. Z> find @attr 1=/GENUS/MEANING @or vertebra jaw Number of hits: 1 Z> format xml Z> show 1 Z> show 1 <GENUS name="Hudiesaurus" type="with" xmlns:idzebra="http://www.indexdata.dk/zebra/"> <MEANING> butterfly <LOW>vertebra</LOW> lizard </MEANING> <LENGTH value="30"></LENGTH> <PLACE name="China"></PLACE> <REMAINS content="4 teeth, forelimb, first dorsal vertebra"></REMAINS> <SPECIES name="sinojapanorum" status="nudum"> <AUTHOR name="Dong" year="1997"></AUTHOR> <MEANING> Chinese-Japanese </MEANING> </SPECIES> <idzebra:size>359</idzebra:size><idzebra:localnumber>447</idzebra:localnumber><idzebra:filename>records/genera.xml</idzebra:filename></GENUS> |
Now wasn't that easy?