1#!/usr/bin/perl -w
2
3=head1 NAME
4
5t/index1.t - test Plucene::Simple with larger files
6
7=head1 DESCRIPTION
8
9In order to index bigger files, this builds and index using
10Plucene::Simple's own test scripts.
11
12=cut
13
14use strict;
15use warnings;
16
17use Plucene::Simple;
18
19use File::Find::Rule;
20use File::Path;
21use File::Slurp;
22
23use Test::More tests => 4;
24
25use constant DIRECTORY => "/tmp/testindex$$";
26
27END { rmtree DIRECTORY }
28
29#------------------------------------------------------------------------------
30# Helper stuff
31#------------------------------------------------------------------------------
32
33sub files { File::Find::Rule->file()->name('*.t')->in('.') }
34
35#------------------------------------------------------------------------------
36# Tests
37#------------------------------------------------------------------------------
38
39our @files = files();
40
41{    # Add some stuff into the index
42	isa_ok my $plucy = Plucene::Simple->open(DIRECTORY) => 'Plucene::Simple';
43
44	#my @files = files();
45	for my $file (@files) {
46		my $data = read_file($file);
47		$plucy->index_document($file, $data);
48	}
49	$plucy->optimize;
50}
51
52{    # search the index
53	my $plucy = Plucene::Simple->open(DIRECTORY);
54	my @docs  = $plucy->search("bogus");
55	is @docs, 2, "2 results for bogus";
56}
57
58{    # is indexed?
59	my $plucy = Plucene::Simple->open(DIRECTORY);
60	ok $plucy->indexed($files[0]), "$files[0] is indexed";
61	ok !$plucy->indexed('NotTheRealID'), "Fake id is not indexed";
62}
63