Fix build with xapian-core < 1.4.10
[xapian.git] / search-xapian / Xapian / PositionIterator.pm
blob1250f743ddafbd1ca020df5d29ab6acfddfef26c
1 package Search::Xapian::PositionIterator;
3 use 5.006;
4 use strict;
5 use warnings;
6 use Carp;
7 use Scalar::Util 'blessed';
9 require DynaLoader;
11 our @ISA = qw(DynaLoader);
13 # Preloaded methods go here.
15 # In a new thread, copy objects of this class to unblessed, undef values.
16 sub CLONE_SKIP { 1 }
18 use overload '++' => sub { $_[0]->inc() },
19 '=' => sub { $_[0]->clone() },
20 'eq' => sub { $_[0]->equal($_[1]) },
21 'ne' => sub { $_[0]->nequal($_[1]) },
22 '==' => sub { $_[0]->equal($_[1]) },
23 '!=' => sub { $_[0]->nequal($_[1]) },
24 '""' => sub { $_[0]->get_description() },
25 '0+' => sub { $_[0]->get_termpos() },
26 'fallback' => 1;
28 sub clone() {
29 my $self = shift;
30 my $class = ref( $self );
31 my $copy = new2( $self );
32 bless $copy, $class;
33 return $copy;
36 sub equal() {
37 my ($self, $other) = @_;
38 if( blessed($other) && $other->isa('Search::Xapian::PositionIterator') ) {
39 $self->equal1($other);
40 } else {
41 ($self+0) == ($other+0);
45 sub nequal() {
46 my ($self, $other) = @_;
47 if( blessed($other) && $other->isa('Search::Xapian::PositionIterator') ) {
48 $self->nequal1($other);
49 } else {
50 ($self+0) != ($other+0);
55 sub new() {
56 my $class = shift;
57 my $iterator;
58 my $invalid_args;
59 if( scalar(@_) == 0 ) {
60 $iterator = new1();
61 } elsif( scalar(@_) == 1 and ref( $_[1] ) eq $class ) {
62 $iterator = new2(@_);
63 } else {
64 $invalid_args = 1;
66 if( $invalid_args ) {
67 Carp::carp( "USAGE: $class->new(), $class->new(\$iterator)" );
68 exit;
70 bless $iterator, $class;
71 return $iterator;
76 __END__
78 =head1 NAME
80 Search::Xapian::PositionIterator - Iterate over sets of positions.
82 =head1 DESCRIPTION
84 This iterator represents a stream of positions for a term. It overloads
85 C<++> for advancing the iterator, or you can explicitly call the C<inc> method.
86 This class also overloads C<eq>, C<ne>, C<==>, C<!=>, C<"">
87 (stringification) and C<0+> (conversion to an integer).
89 =head1 METHODS
91 =over 4
93 =item new
95 Constructor. Defaults to an uninitialized iterator.
97 =item clone
99 =item inc
101 Advance the iterator by one. (Called implictly by C<++> overloading).
103 =item skip_to <termpos>
105 Skip the iterator to term position termpos, or the first term position after
106 termpos if termpos isn't in the list of term positions being iterated.
108 =item equal <term>
110 Checks if a term is the same as this term. Also overloaded to the C<eq>
111 and C<==> operators.
113 =item nequal <term>
115 Checks if a term is different from this term. Also overloaded to the C<ne>
116 and C<!=> operators.
118 =item get_termpos
120 Return the term position the iterator is currently on. Also implemented as
121 conversion to an integer.
123 =item get_description
125 Return a description of this object. Also implemented as stringification.
127 =back
129 =head1 SEE ALSO
131 L<Search::Xapian>,
132 L<Search::Xapian::Document>
134 =cut