Plucene

 view release on metacpan or  search on metacpan

lib/Plucene/TestCase.pm  view on Meta::CPAN

Create a new index, and do the following stuff in the block before
closing the index writer. C<$WRITER> is set for the duration of the
block.

The optional parameter should be the class name of the analyzer to use;
if not specified, the value from C<$ANALYZER>, which in turn defaults to
C<Plucene::Analysis::SimpleAnalyzer>, will be used.

=cut

sub new_index(&;$) {
	my ($block, $analyzer) = @_;
	$analyzer ||= $ANALYZER;

	# UNIVERSAL::require loads UNIVERSAL->import, which won't do.
	eval "require $analyzer";
	die "Couldn't require $analyzer" if $@;
	$WRITER = Plucene::Index::Writer->new($DIR, $analyzer->new, 1);
	$block->();
	undef $WRITER;
}

=item re_index BLOCK (Analyzer)

Same as C<new_index>, but doesn't create a new index, rather re-uses an
old one.

=cut

sub re_index(&;$) {
	my ($block, $analyzer) = @_;
	$analyzer ||= $ANALYZER;
	eval "require $analyzer";
	die "Couldn't require $analyzer" if $@;
	$WRITER = Plucene::Index::Writer->new($DIR, $analyzer->new, 0);
	$block->();
	undef $WRITER;
}

=item add_document( field1 => value1, ...)



( run in 0.246 second using v1.01-cache-2.11-cpan-49f99fa48dc )