1#!/usr/bin/perl -w
2
3=head1 NAME
4
5t/datesearch.t - test Plucene::Simple
6
7=head1 DESCRIPTION
8
9Tests the search_during ability of Plucene::Simple.
10
11=cut
12
13use strict;
14use warnings;
15
16use Plucene::Simple;
17
18use File::Path;
19use Test::More tests => 8;
20use Time::Piece;
21
22use constant DIRECTORY => "/tmp/testindex/$$";
23
24END { rmtree DIRECTORY }
25
26#------------------------------------------------------------------------------
27# Helper stuff
28#------------------------------------------------------------------------------
29
30sub data {
31	return [
32		wsc => { name => "Writing Solid Code", date => Time::Piece->new->ymd },
33		rap => { name => "Rapid Development" },
34		gui => { name => "GUI Bloopers",       date => "1972-06-15" },
35		ora => { name => "Using Oracle 8i" },
36		app => { name => "Advanced Perl Programming", date => "1996-07-05" },
37		xpe => { name => "Extreme Programming Explained" },
38		boo => { name => "Boo-Hoo",                   date => "1996-03-19" },
39		dbs => { name => "Designing From Both Sides of the Screen" },
40		dbi => { name => "Programming the Perl DBI", date => "1998-03-17" },
41	];
42}
43
44#------------------------------------------------------------------------------
45# Tests
46#------------------------------------------------------------------------------
47
48{    # Add some stuff into the index
49	my @data = @{ data() };
50	isa_ok my $plucy = Plucene::Simple->open(DIRECTORY) => 'Plucene::Simple';
51	$plucy->add(@data);
52}
53
54{    # search the index between 1972 - 1998
55	my $plucy = Plucene::Simple->open(DIRECTORY);
56	my @docs = $plucy->search_during("name:perl", "1972-06-01", "1998-12-25");
57	is @docs, 2, "2 results for Perl between 1972 and 1998";
58	is_deeply \@docs, [ "dbi", "app" ], "The correct ones";
59}
60
61{    # search the index between 1997 - 1998
62	my $plucy = Plucene::Simple->open(DIRECTORY);
63	my @docs = $plucy->search_during("name:perl", "1997-01-01", "1998-12-25");
64	is @docs, 1, "1 result for Perl between 1997 and 1998";
65	is_deeply \@docs, ["dbi"], "The correct one";
66}
67
68{    # search the index between 1997 - 1998 (dates passed in different order)
69	my $plucy = Plucene::Simple->open(DIRECTORY);
70	my @docs = $plucy->search_during("name:perl", "1998-12-25", "1997-01-01");
71	is @docs, 1, "1 result for Perl between 1997 and 1998";
72	is_deeply \@docs, ["dbi"], "The correct one";
73}
74
75{    # search the index between post 1998
76	my $plucy = Plucene::Simple->open(DIRECTORY);
77	my @docs  =
78		$plucy->search_during("name:perl", "1998-12-25", Time::Piece->new->ymd);
79	is @docs, 0, "No results for Perl between 1998 and now";
80}
81
82