1 # $Id: ScanList.pm,v 1.3 2003-03-12 17:08:53 pop Exp $
3 # Zebra perl API header
4 # =============================================================================
5 package IDZebra::ScanList;
12 use IDZebra::Logger qw(:flags :calls);
13 use IDZebra::ScanEntry;
14 use Scalar::Util qw(weaken);
16 our $VERSION = do { my @r = (q$Revision: 1.3 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
17 our @ISA = qw(IDZebra::Logger);
21 # -----------------------------------------------------------------------------
22 # Class constructors, destructor
23 # -----------------------------------------------------------------------------
25 my ($proto,$session, %args) = @_;
26 my $class = ref($proto) || $proto;
28 bless ($self, $class);
30 $self->{session} = $session;
31 weaken ($self->{session});
33 $self->{expression} = $args{expression};
34 $self->{databases} = $args{databases};
36 $self->{so} = IDZebra::ScanObj->new();
38 $self->{odr_stream} = IDZebra::odr_createmem($IDZebra::ODR_DECODE);
40 $self->entries(num_entries => 0);
48 # logf(LOG_LOG,"DESTROY: IDZebra::ScanList");
50 if ($self->{odr_stream}) {
51 IDZebra::odr_reset($self->{odr_stream});
52 IDZebra::odr_destroy($self->{odr_stream});
53 $self->{odr_stream} = undef;
57 delete($self->{session});
60 # =============================================================================
63 return ($self->{so}{is_partial});
68 return ($self->{so}{position});
73 return ($self->{so}{num_entries});
78 return ($self->{session}->errCode);
83 return ($self->{session}->errString);
86 # -----------------------------------------------------------------------------
88 my ($self, %args) = @_;
90 unless ($self->{session}{zh}) {
91 croak ("Session is closed or out of scope");
96 $so->{position} = defined($args{position}) ? $args{position} : 1;
97 $so->{num_entries} = defined($args{num_entries}) ? $args{num_entries} : 20;
100 if ($self->{databases}) {
101 @origdbs = $self->{session}->databases;
102 $self->{session}->databases(@{$self->{databases}});
105 $so->{is_partial} = 0;
107 my $r = IDZebra::scan_PQF($self->{session}{zh}, $so,
109 $self->{expression});
111 if ($self->{session}->errCode) {
112 croak ("Error in scan, code: ".$self->{session}->errCode .
113 ", message: ".$self->{session}->errString);
117 for (my $i=1; $i<=$so->{num_entries}; $i++) {
118 my $se = IDZebra::getScanEntry($so, $i);
120 IDZebra::ScanEntry->new($se->{term},
126 if ($self->{databases}) {
127 $self->{session}->databases(@origdbs);
130 IDZebra::odr_reset($self->{odr_stream});
138 # ============================================================================
143 IDZebra::ScanList - Scan results
147 $sl = $sess->scan(expression => "\@attr 1=4 \@attr 6=2 a",
148 databases => [qw(demo1 demo2)]);
150 @entries = $sl->entries(position => 5,
161 The scan list object is the result of a scan call, and can be used to retrieve entries from the list. To do this, use the B<entries> method,
163 @entries = $sl->entries(position => 5,
166 returning an array of I<IDZebra::ScanEntry> objects.
167 The possible arguments are:
173 The requested position of the scanned term in the returned list. For example, if position 5 is given, and the scan term is "a", then the entry corresponding to term "a" will be on the position 5 of the list (4th. elment of the array). It may happen, that due to the position of term in the whole index, it's not possible to put the entry on the requested position (for example, the term is on the 2nd position of the index), this case I<$sl-E<gt>position> will contain a different value, presenting the actual position. The default value is 1.
177 The requested number of entries in the list. See I<$sl-E<gt>num_entries> for the actual number of fetched entries. The dafault value is 20.
183 You can reach the following properties as function calls on the IDZebra::ScanList object:
189 After calling I<entries>, the actual position of the requested term.
193 After calling I<entries>, the actual number of entries returned.
197 Only partial list is returned by I<entries>.
207 Peter Popovics, pop@technomat.hu
211 Zebra documentation, IDZebra::Session manpage.