Plucene::Search::PhrasePositions - The position of a phrase


Plucene documentation Contained in the Plucene distribution.

Index


Code Index:

NAME

Top

Plucene::Search::PhrasePositions - The position of a phrase

SYNOPSIS

Top

	my $phpos = Plucene::Search::PhrasePositions->new;

	my      $next = $phpos->next;
	my $first_pos = $phpos->first_position;
	my  $next_pos = $phpos->next_position;

DESCRIPTION

Top

METHODS

Top

new

	my $phpos = Plucene::Search::PhrasePositions->new;

Make a new Plucene::Search::PhrasePositions object.

doc / position / count / offset / tp / next

Get / set these attibutes.

next

	my $next = $phpos->next;

first_position

	my $first = $phpos->first_position;

next_position

	my $next_pos = $phpos->next_position;


Plucene documentation Contained in the Plucene distribution.
package Plucene::Search::PhrasePositions;

use strict;
use warnings;

use base 'Class::Accessor::Fast';

__PACKAGE__->mk_accessors(qw/ doc position count offset tp next_in_list /);

sub new {
	my $self = shift->SUPER::new(@_);
	$self->{offset}   ||= 0;
	$self->{position} ||= 0;
	$self->{count}    ||= 0;
	$self->next;
	$self;
}

sub next {
	my $self = shift;
	if (!$self->{tp}->next) {
		$self->doc(~0);
		return;
	}
	$self->doc($self->tp->doc);
	$self->position(0);
}

sub first_position {
	my $self = shift;
	$self->count($self->tp->freq);
	$self->next_position;
}

sub next_position {
	my $self = shift;
	return unless $self->{count}-- > 0;
	$self->position($self->tp->next_position - $self->offset);
}

1;