1 # $Id: Session.pm,v 1.14 2003-03-12 17:08:53 pop Exp $
3 # Zebra perl API header
4 # =============================================================================
5 package IDZebra::Session;
13 use IDZebra::Logger qw(:flags :calls);
14 use IDZebra::Resultset;
15 use IDZebra::ScanList;
16 use IDZebra::RetrievalRecord;
18 our $VERSION = do { my @r = (q$Revision: 1.14 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
19 our @ISA = qw(IDZebra::Logger Exporter);
20 our @EXPORT = qw (TRANS_RW TRANS_RO);
23 use constant TRANS_RW => 1;
24 use constant TRANS_RO => 0;
27 # -----------------------------------------------------------------------------
28 # Class constructors, destructor
29 # -----------------------------------------------------------------------------
31 my ($proto, %args) = @_;
32 my $class = ref($proto) || $proto;
34 $self->{args} = \%args;
36 bless ($self, $class);
37 $self->{cql_ct} = undef;
38 $self->{cql_mapfile} = "";
41 $self->{databases} = {};
45 my ($self, %args) = @_;
48 unless (defined($self->{zs})) {
49 if (defined($args{'configFile'})) {
50 $self->{zs} = IDZebra::start($args{'configFile'});
52 $self->{zs} = IDZebra::start("zebra.cfg");
59 if (defined($self->{zs})) {
60 IDZebra::stop($self->{zs}) if ($self->{zs});
67 my ($proto,%args) = @_;
70 if (ref($proto)) { $self = $proto; } else {
71 $self = $proto->new(%args);
75 %args = %{$self->{args}};
78 $self->start_service(%args);
80 unless (defined($self->{zs})) {
81 croak ("Falied to open zebra service");
84 unless (defined($self->{zh})) {
85 $self->{zh}=IDZebra::open($self->{zs});
88 # Reset result set counter
91 # This is needed in order to somehow initialize the service
92 $self->databases("Default");
94 # Load the default configuration
99 my $shadow = defined($args{shadow}) ? $args{shadow} : 0;
100 $self->shadow($shadow);
102 $self->{odr_input} = IDZebra::odr_createmem($IDZebra::ODR_DECODE);
103 $self->{odr_output} = IDZebra::odr_createmem($IDZebra::ODR_ENCODE);
110 unless (defined($self->{zh})) {
111 croak ("Zebra session is not opened");
121 # Delete all resulsets
122 my $r = IDZebra::deleteResultSet($self->{zh},
123 1, #Z_DeleteRequest_all,
127 while (IDZebra::trans_no($self->{zh}) > 0) {
128 logf (LOG_WARN,"Explicitly closing transaction with session");
132 IDZebra::close($self->{zh});
136 if ($self->{odr_input}) {
137 IDZebra::odr_reset($self->{odr_input});
138 IDZebra::odr_destroy($self->{odr_input});
139 $self->{odr_input} = undef;
142 if ($self->{odr_output}) {
143 IDZebra::odr_reset($self->{odr_output});
144 IDZebra::odr_destroy($self->{odr_output});
145 $self->{odr_output} = undef;
153 logf (LOG_LOG,"DESTROY $self");
156 if (defined ($self->{cql_ct})) {
157 IDZebra::cql_transform_close($self->{cql_ct});
161 # -----------------------------------------------------------------------------
162 # Record group selection This is a bit nasty... but used at many places
163 # -----------------------------------------------------------------------------
165 my ($self,%args) = @_;
168 $self->{rg} = $self->_makeRecordGroup(%args);
169 $self->_selectRecordGroup($self->{rg});
174 sub selectRecordGroup {
175 my ($self, $groupName) = @_;
177 $self->{rg} = $self->_getRecordGroup($groupName);
178 $self->_selectRecordGroup($self->{rg});
181 sub _displayRecordGroup {
182 my ($self, $rg) = @_;
183 print STDERR "-----\n";
184 foreach my $key qw (groupName
195 print STDERR "$key:",$rg->{$key},"\n";
199 sub _cloneRecordGroup {
200 my ($self, $orig) = @_;
201 my $rg = IDZebra::recordGroup->new();
202 my $r = IDZebra::init_recordGroup($rg);
203 foreach my $key qw (groupName
215 $rg->{$key} = $orig->{$key} if ($orig->{$key});
220 sub _getRecordGroup {
221 my ($self, $groupName, $ext) = @_;
222 my $rg = IDZebra::recordGroup->new();
223 my $r = IDZebra::init_recordGroup($rg);
224 $rg->{groupName} = $groupName if ($groupName ne "");
225 $ext = "" unless ($ext);
226 $r = IDZebra::res_get_recordGroup($self->{zh}, $rg, $ext);
230 sub _makeRecordGroup {
231 my ($self, %args) = @_;
234 my @keys = keys(%args);
235 unless ($#keys >= 0) {
236 return ($self->{rg});
239 if ($args{groupName}) {
240 $rg = $self->_getRecordGroup($args{groupName});
242 $rg = $self->_cloneRecordGroup($self->{rg});
244 $self->_setRecordGroupOptions($rg, %args);
248 sub _setRecordGroupOptions {
249 my ($self, $rg, %args) = @_;
251 foreach my $key qw (databaseName
262 if (defined ($args{$key})) {
263 $rg->{$key} = $args{$key};
267 sub _selectRecordGroup {
268 my ($self, $rg) = @_;
270 my $r = IDZebra::set_group($self->{zh}, $rg);
272 unless ($dbName = $rg->{databaseName}) {
275 unless ($self->databases($dbName)) {
276 croak("Fatal error selecting database $dbName");
279 # -----------------------------------------------------------------------------
280 # Selecting databases for search (and also for updating - internally)
281 # -----------------------------------------------------------------------------
283 my ($self, @databases) = @_;
288 return (keys(%{$self->{databases}}));
293 foreach my $db (@databases) {
295 next if ($self->{databases}{$db});
299 foreach my $db (keys (%{$self->{databases}})) {
300 $changed++ unless ($tmp{$db});
305 delete ($self->{databases});
306 foreach my $db (@databases) {
307 $self->{databases}{$db}++;
310 if (IDZebra::select_databases($self->{zh},
314 "Could not select database(s) %s errCode=%d",
315 join(",",@databases),
319 logf(LOG_LOG,"Database(s) selected: %s",join(",",@databases));
322 return (keys(%{$self->{databases}}));
325 # -----------------------------------------------------------------------------
327 # -----------------------------------------------------------------------------
330 return(IDZebra::errCode($self->{zh}));
335 return(IDZebra::errString($self->{zh}));
340 return(IDZebra::errAdd($self->{zh}));
343 # -----------------------------------------------------------------------------
345 # -----------------------------------------------------------------------------
348 $m = TRANS_RW unless (defined ($m));
349 if (my $err = IDZebra::begin_trans($self->{zh},$m)) {
350 if ($self->errCode == 2) {
351 croak ("TRANS_RW not allowed within TRANS_RO");
353 croak("Error starting transaction; code:".
354 $self->errCode . " message: " . $self->errString);
362 my $stat = IDZebra::ZebraTransactionStatus->new();
363 IDZebra::end_trans($self->{zh}, $stat);
368 my ($self, $value) = @_;
371 $value = 0 unless (defined($value));
372 my $r =IDZebra::set_shadow_enable($self->{zh},$value);
374 return (IDZebra::get_shadow_enable($self->{zh}));
381 return(IDZebra::commit($self->{zh}));
385 # -----------------------------------------------------------------------------
386 # We don't really need that...
387 # -----------------------------------------------------------------------------
389 my ($self, $name) = @_;
390 if ($name !~/^(input|output)$/) {
391 croak("Undefined ODR '$name'");
393 IDZebra::odr_reset($self->{"odr_$name"});
396 # -----------------------------------------------------------------------------
398 # -----------------------------------------------------------------------------
402 return(IDZebra::init($self->{zh}));
408 return(IDZebra::compact($self->{zh}));
412 my ($self, %args) = @_;
414 my $rg = $self->_update_args(%args);
415 $self->_selectRecordGroup($rg);
417 IDZebra::repository_update($self->{zh});
418 $self->_selectRecordGroup($self->{rg});
423 my ($self, %args) = @_;
425 my $rg = $self->_update_args(%args);
426 $self->_selectRecordGroup($rg);
428 IDZebra::repository_delete($self->{zh});
429 $self->_selectRecordGroup($self->{rg});
434 my ($self, %args) = @_;
436 my $rg = $self->_update_args(%args);
437 $self->_selectRecordGroup($rg);
439 IDZebra::repository_show($self->{zh});
440 $self->_selectRecordGroup($self->{rg});
445 my ($self, %args) = @_;
446 my $rg = $self->_makeRecordGroup(%args);
447 $self->_selectRecordGroup($rg);
451 # -----------------------------------------------------------------------------
453 # -----------------------------------------------------------------------------
456 my ($self, %args) = @_;
458 return(IDZebra::update_record($self->{zh},
459 $self->_record_update_args(%args)));
463 my ($self, %args) = @_;
465 return(IDZebra::delete_record($self->{zh},
466 $self->_record_update_args(%args)));
469 sub _record_update_args {
470 my ($self, %args) = @_;
472 my $sysno = $args{sysno} ? $args{sysno} : 0;
473 my $match = $args{match} ? $args{match} : "";
474 my $rectype = $args{recordType} ? $args{recordType} : "";
475 my $fname = $args{file} ? $args{file} : "<no file>";
476 my $force = $args{force} ? $args{force} : 0;
483 elsif ($args{file}) {
484 CORE::open (F, $args{file}) || warn ("Cannot open $args{file}");
485 $buff = join('',(<F>));
488 my $len = length($buff);
490 delete ($args{sysno});
491 delete ($args{match});
492 delete ($args{recordType});
493 delete ($args{file});
494 delete ($args{data});
495 delete ($args{force});
497 my $rg = $self->_makeRecordGroup(%args);
499 # If no record type is given, then try to find it out from the
502 if (my ($ext) = $fname =~ /\.(\w+)$/) {
503 my $rg2 = $self->_getRecordGroup($rg->{groupName},$ext);
504 $rectype = $rg2->{recordType};
508 $rg->{databaseName} = "Default" unless ($rg->{databaseName});
513 return ($rg, $rectype, $sysno, $match, $fname, $buff, $len, $force);
516 # -----------------------------------------------------------------------------
519 my ($self,$mapfile) = @_;
521 if ($self->{cql_mapfile} ne $mapfile) {
522 unless (-f $mapfile) {
523 croak("Cannot find $mapfile");
525 if (defined ($self->{cql_ct})) {
526 IDZebra::cql_transform_close($self->{cql_ct});
528 $self->{cql_ct} = IDZebra::cql_transform_open_fname($mapfile);
529 $self->{cql_mapfile} = $mapfile;
532 return ($self->{cql_mapfile});
536 my ($self, $cqlquery) = @_;
537 unless (defined($self->{cql_ct})) {
538 croak("CQL map file is not specified yet.");
540 my $res = "\0" x 2048;
541 my $r = IDZebra::cql2pqf($self->{cql_ct}, $cqlquery, $res, 2048);
543 carp ("Error transforming CQL query: '$cqlquery', status:$r");
550 # -----------------------------------------------------------------------------
552 # -----------------------------------------------------------------------------
554 my ($self, %args) = @_;
558 if ($args{cqlmap}) { $self->cqlmap($args{cqlmap}); }
566 ($query, $cqlstat) = $self->cql2pqf($args{cql});
568 croak ("Failed to transform query: '$args{cql}', ".
569 "status: ($cqlstat)");
573 croak ("No query given to search");
578 if ($args{databases}) {
579 @origdbs = $self->databases;
580 $self->databases(@{$args{databases}});
583 my $rsname = $args{rsname} ? $args{rsname} : $self->_new_setname;
585 my $rs = $self->_search_pqf($query, $rsname);
587 if ($args{databases}) {
588 $self->databases(@origdbs);
593 carp("Sort skipped due to search error: ".
596 $rs->sort($args{sort});
605 return ("set_".$self->{rscount}++);
609 my ($self, $query, $setname) = @_;
611 my $hits = IDZebra::search_PQF($self->{zh},
617 my $rs = IDZebra::Resultset->new($self,
619 recordCount => $hits,
620 errCode => $self->errCode,
621 errString => $self->errString);
625 # -----------------------------------------------------------------------------
628 # Sorting of multiple result sets is not supported by zebra...
629 # -----------------------------------------------------------------------------
632 my ($self, $sortspec, $setname, @sets) = @_;
637 croak ("Sorting/merging of multiple resultsets is not supported now");
642 foreach my $rs (@sets) {
643 push (@setnames, $rs->{name});
644 $count += $rs->{recordCount}; # is this really sure ??? It doesn't
648 my $status = IDZebra::sort($self->{zh},
654 my $errCode = $self->errCode;
655 my $errString = $self->errString;
657 logf (LOG_LOG, "Sort status $setname: %d, errCode: %d, errString: %s",
658 $status, $errCode, $errString);
660 if ($status || $errCode) {$count = 0;}
662 my $rs = IDZebra::Resultset->new($self,
664 recordCount => $count,
666 errString => $errString);
670 # -----------------------------------------------------------------------------
672 # -----------------------------------------------------------------------------
674 my ($self, %args) = @_;
678 unless ($args{expression}) {
679 croak ("No scan expression given");
682 my $sl = IDZebra::ScanList->new($self,%args);
687 # ============================================================================
693 IDZebra::Session - A Zebra database server session for update and retrieval
697 $sess = IDZebra::Session->new(configFile => 'demo/zebra.cfg');
700 $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
701 groupName => 'demo1');
703 $sess->group(groupName => 'demo2');
709 $sess->update(path => 'lib');
711 my $s1=$sess->update_record(data => $rec1,
712 recordType => 'grs.perl.pod',
713 groupName => "demo1",
716 my $stat = $sess->end_trans;
718 $sess->databases('demo1','demo2');
720 my $rs1 = $sess->search(cqlmap => 'demo/cql.map',
721 cql => 'dc.title=IDZebra',
722 databases => [qw(demo1 demo2)]);
727 Zebra is a high-performance, general-purpose structured text indexing and retrieval engine. It reads structured records in a variety of input formats (eg. email, XML, MARC) and allows access to them through exact boolean search expressions and relevance-ranked free-text queries.
729 Zebra supports large databases (more than ten gigabytes of data, tens of millions of records). It supports incremental, safe database updates on live systems. You can access data stored in Zebra using a variety of Index Data tools (eg. YAZ and PHP/YAZ) as well as commercial and freeware Z39.50 clients and toolkits.
731 =head1 OPENING AND CLOSING A ZEBRA SESSIONS
733 For the time beeing only local database services are supported, the same way as calling zebraidx or zebrasrv from the command shell. In order to open a local Zebra database, with a specific configuration file, use
735 $sess = IDZebra::Session->new(configFile => 'demo/zebra.cfg');
740 $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg');
742 where $sess is going to be the object representing a Zebra Session. Whenever this variable gets out of scope, the session is closed, together with all active transactions, etc... Anyway, if you'd like to close the session, just say:
747 - close all transactions
748 - destroy all result sets and scan lists
751 Note, that if I<shadow registers> are enabled, the changes will not be committed automatically.
753 In the future different database access methods are going to be available,
756 $sess = IDZebra::Session->open(server => 'ostrich.technomat.hu:9999');
758 You can also use the B<record group> arguments described below directly when calling the constructor, or the open method:
760 $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
761 groupName => 'demo');
766 If you manage different sets of records that share common characteristics, you can organize the configuration settings for each type into "groups". See the Zebra manual on the configuration file (zebra.cfg).
768 For each open session a default record group is assigned. You can configure it in the constructor, or by the B<group> method:
770 $sess->group(groupName => ..., ...)
772 The following options are available:
778 This will select the named record group, and load the corresponding settings from the configuration file. All subsequent values will overwrite those...
780 =item B<databaseName>
782 The name of the (logical) database the updated records will belong to.
786 This path is used for directory updates (B<update>, B<delete> methods);
790 This option determines how to identify your records. See I<Zebra manual: Locating Records>
794 The record type used for indexing.
796 =item B<flagStoreData>
798 Specifies whether the records should be stored internally in the Zebra system files. If you want to maintain the raw records yourself, this option should be false (0). If you want Zebra to take care of the records for you, it should be true(1).
800 =item B<flagStoreKeys>
802 Specifies whether key information should be saved for a given group of records. If you plan to update/delete this type of records later this should be specified as 1; otherwise it should be 0 (default), to save register space.
808 =item B<fileVerboseLimit>
810 Skip log messages, when doing a directory update, and the specified number of files are processed...
812 =item B<databaseNamePath>
816 =item B<explainDatabase>
818 The name of the explain database to be used
822 Follow links when doing directory update.
826 You can use the same parameters calling all update methods.
828 =head1 TRANSACTIONS (READ / WRITE LOCKS)
830 A transaction is a block of record update (insert / modify / delete) or retrieval procedures. So, all call to such function will implicitly start a transaction, unless one is already started by
836 $sess->begin_trans(TRANS_RW)
838 (these two are equivalents). The effect of this call is a kind of lock: if you call is a write lock is put on the registers, so other processes trying to update the database will be blocked. If there is already an RW (Read-Write) transaction opened by another process, the I<begin_trans> call will be blocked.
842 $sess->begin_trans(TRANS_RO),
844 if you would like to put on a "read lock". This one is B<deprecated>, as while you have explicitly opened a transaction for read, you can't open another one for update. For example:
846 $sess->begin_trans(TRANS_RO);
847 $sess->begin_tran(TRANS_RW); # invalid, die here
853 $sess->begin_tran(TRANS_RW);
854 $sess->begin_trans(TRANS_RO);
858 is valid, but probably useless. Note again, that for each retrieval call, an RO transaction is opened. I<TRANS_RW> and I<TRANS_RO> are exported by default by IDZebra::Session.pm.
860 For multiple per-record I<updates> it's efficient to start transactions explicitly: otherwise registers (system files, vocabularies, etc..) are updated one by one. After finishing all requested updates, use
862 $stat = $sess->end_trans;
864 The return value is a ZebraTransactionStatus object, containing the following members as a hash reference:
866 $stat->{processed} # Number of records processed
867 $stat->{updated} # Number of records processed
868 $stat->{deleted} # Number of records processed
869 $stat->{inserted} # Number of records processed
870 $stat->{stime} # System time used
871 $stat->{utime} # User time used
873 Normally, if the perl code dies due to some runtime error, or the session is closed, then the API attempts to close all pending transactions.
875 =head1 THE SHADOW REGISTERS
877 The Zebra server supports updating of the index structures. That is, you can add, modify, or remove records from databases managed by Zebra without rebuilding the entire index. Since this process involves modifying structured files with various references between blocks of data in the files, the update process is inherently sensitive to system crashes, or to process interruptions: Anything but a successfully completed update process will leave the register files in an unknown state, and you will essentially have no recourse but to re-index everything, or to restore the register files from a backup medium. Further, while the update process is active, users cannot be allowed to access the system, as the contents of the register files may change unpredictably.
879 You can solve these problems by enabling the shadow register system in Zebra. During the updating procedure, zebraidx will temporarily write changes to the involved files in a set of "shadow files", without modifying the files that are accessed by the active server processes. If the update procedure is interrupted by a system crash or a signal, you simply repeat the procedure - the register files have not been changed or damaged, and the partially written shadow files are automatically deleted before the new updating procedure commences.
881 At the end of the updating procedure (or in a separate operation, if you so desire), the system enters a "commit mode". First, any active server processes are forced to access those blocks that have been changed from the shadow files rather than from the main register files; the unmodified blocks are still accessed at their normal location (the shadow files are not a complete copy of the register files - they only contain those parts that have actually been modified). If the commit process is interrupted at any point during the commit process, the server processes will continue to access the shadow files until you can repeat the commit procedure and complete the writing of data to the main register files. You can perform multiple update operations to the registers before you commit the changes to the system files, or you can execute the commit operation at the end of each update operation. When the commit phase has completed successfully, any running server processes are instructed to switch their operations to the new, operational register, and the temporary shadow files are deleted.
883 By default, (in the API !) the use of shadow registers is disabled. If zebra is configured that way (there is a "shadow" entry in zebra.cfg), then the shadow system can be enabled by calling:
891 If shadow system is enabled, then you have to commit changes you did, by calling:
895 Note, that you can also determine shadow usage in the session constructor:
897 $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
900 Changes to I<shadow> will not have effect, within a I<transaction> (ie.: a transaction is started either with shadow enabled or disabled). For more details, read Zebra documentation: I<Safe Updating - Using Shadow Registers>.
904 There are two ways to update data in a Zebra database using the perl API. You can update an entire directory structure just the way it's done by zebraidx:
906 $sess->update(path => 'lib');
908 This will update the database with the files in directory "lib", according to the current record group settings.
912 This will update the database with the files, specified by the default record group setting. I<path> has to be specified there...
914 $sess->update(groupName => 'demo1',
917 Update the database with files in "lib" according to the settings of group "demo1"
919 $sess->delete(groupName => 'demo1',
922 Delete the records derived from the files in directory "lib", according to the "demo1" group settings. Sounds complex? Read zebra documentation about identifying records.
924 You can also update records one by one, even directly from the memory:
926 $sysno = $sess->update_record(data => $rec1,
927 recordType => 'grs.perl.pod',
928 groupName => "demo1");
930 This will update the database with the given record buffer. Note, that in this case recordType is explicitly specified, as there is no filename given, and for the demo1 group, no default record type is specified. The return value is the system assigned id of the record.
932 You can also index a single file:
934 $sysno = $sess->update_record(file => "lib/IDZebra/Data1.pm");
936 Or, provide a buffer, and a filename (where filename will only be used to identify the record, if configured that way, and possibly to find out it's record type):
938 $sysno = $sess->update_record(data => $rec1,
939 file => "lib/IDZebra/Data1.pm");
941 And some crazy stuff:
943 $sysno = $sess->delete_record(sysno => $sysno);
945 where sysno in itself is sufficient to identify the record
947 $sysno = $sess->delete_record(data => $rec1,
948 recordType => 'grs.perl.pod',
949 groupName => "demo1");
951 This case the record is extracted, and if already exists, located in the database, then deleted...
953 $sysno = $sess->delete_record(data => $rec1,
955 recordType => 'grs.perl.pod',
956 groupName => "demo1");
958 Don't try this at home! This case, the record identifier string (which is normally generated according to the rules set in recordId directive of zebra.cfg) is provided directly....
961 B<Important:> Note, that one record can be updated only once within a transaction - all subsequent updates are skipped.
963 =head1 DATABASE SELECTION
965 Within a zebra repository you can define logical databases. You can either do this by record groups, or by providing the databaseName argument for update methods. For each record the database name it belongs to is stored.
967 For searching, you can select databases by calling:
969 $sess->databases('db1','db2');
971 This will not do anything if the given and only the given databases are already selected. You can get the list of the actually selected databases, by calling:
973 @dblist = $sess->databases();
977 It's nice to be able to store data in your repository... But it's useful to reach it as well. So this is how to do searching:
979 $rs = $sess->search(databases => [qw(demo1,demo2)], # optional
980 pqf => '@attr 1=4 computer');
982 This is going to execute a search in databases demo1 and demo2, for title 'com,puter'. This is a PQF (Prefix Query Format) search, see YAZ documentation for details. The database selection is optional: if it's provided, the given list of databases is selected for this particular search, then the original selection is restored.
986 Not all users enjoy typing in prefix query structures and numerical attribute values, even in a minimalistic test client. In the library world, the more intuitive Common Command Language (or ISO 8777) has enjoyed some popularity - especially before the widespread availability of graphical interfaces. It is still useful in applications where you for some reason or other need to provide a symbolic language for expressing boolean query structures.
988 The CCL searching is not currently supported by this API.
992 CQL - Common Query Language - was defined for the SRW protocol. In many ways CQL has a similar syntax to CCL. The objective of CQL is different. Where CCL aims to be an end-user language, CQL is the protocol query language for SRW.
994 In order to map CQL queries to Zebra internal search structures, you have to define a mapping, the way it is described in YAZ documentation: I<Specification of CQL to RPN mapping>. The mapping is interpreted by the method:
996 $sess->cqlmap($mapfile);
998 Or, you can directly provide the I<mapfile> parameter for the search:
1000 $rs = $sess->search(cqlmap => 'demo/cql.map',
1001 cql => 'dc.title=IDZebra');
1003 As you see, CQL searching is so simple: just give the query in the I<cql> parameter.
1007 If you'd like the search results to be sorted, use the I<sort> parameter:
1009 $rs = $sess->search(cql => 'IDZebra',
1012 Note, that B<currently> this is (almost) equivalent to
1014 $rs = $sess->search(cql => 'IDZebra');
1015 $rs->sort('1=4 ia');
1017 but in the further versions of Zebra and this API a single phase search and sort will take place, optimizing performance. For more details on sorting, see I<IDZebra::ResultSet> manpage.
1021 As you have seen, the result of the search request is a I<Resultset> object.
1022 It contains number of hits, and search status, and can be used to sort and retrieve the resulting records.
1024 $count = $rs->count;
1026 printf ("RS Status is %d (%s)\n", $rs->errCode, $rs->errString);
1028 I<$rs-E<gt>errCode> is 0, if there were no errors during search. Read the I<IDZebra::Resultset> manpage for more details.
1032 Zebra supports scanning index values. The result of the
1034 $sl = $sess->scan(expression => "a");
1036 call is an I<IDZebra::ScanList> object, what you can use to list the values. The scan expression has to be provided in a PQF like format. Examples:
1038 B< a> (scan trough words of "default", "Any" indexes)
1041 B< @attr 1=1016 a> (same effect)
1044 B< @attr 1=4 @attr 6=2 a> (scan trough titles as phrases)
1046 An illegal scan expression will cause your code to die. If you'd like to select databases just for the scan call, you can optionally use the I<databases> parameter:
1048 $sl = $sess->scan(expression => "a",
1049 databases => [qw(demo1 demo2)]);
1051 You can use the I<IDZebra::ScanList> object returned by the i<scan> method, to reach the result. Check I<IDZebra::ScanList> manpage for more details.
1053 =head1 SESSION STATUS AND ERRORS
1055 Most of the API calls causes die, if an error occures. You avoid this, by using eval {} blocks. The following methods are available to get the status of Zebra service:
1061 The Zebra provided error code... (for the result of the last call);
1065 Error string corresponding to the message
1069 Additional information for the status
1073 This functionality may change, see TODO.
1075 =head1 LOGGING AND MISC. FUNCTIONS
1077 Zebra provides logging facility for the internal events, and also for application developers trough the API. See manpage I<IDZebra::Logger> for details.
1081 =item B<IDZebra::LogFile($filename)>
1083 Will set the output file for logging. By default it's STDERR;
1085 =item B<IDZebra::LogLevel(15)>
1087 Set log level. 0 for no logs. See IDZebra::Logger for usable flags.
1091 Some other functions
1095 =item B<$sess-E<gt>init>
1097 Initialize, and clean registers. This will remove all data!
1099 =item B<$sess-E<gt>compact>
1101 Compact the registers (? does this work)
1103 =item B<$sess-E<gt>show>
1105 Doesn't have too much meaning. Don't try :)
1113 =item B<Clean up error handling>
1115 By default all zebra errors should cause die. (such situations could be avoided by using eval {}), and then check for errCode, errString... An optional flag or package variable should be introduced to override this, and skip zebra errors, to let the user decide what to do.
1117 =item B<Make the package self-distributable>
1119 Build and link with installed header and library files
1123 Test shadow system, unicode...
1127 Cleanup, arrange, remove redundancy
1137 Peter Popovics, pop@technomat.hu
1141 Zebra documentation, Zebra::ResultSet, Zebra::ScanList, Zebra::Logger manpages