#!/usr/local/bin/perl -w
use strict;
use Test::More tests => 8;
use Search::Xapian qw(:ops);

my $db_name='';
my ( $id1, $id2 ) = ( 123, 2_147_483_648 );
# $id2 is the maximum number i've found...(2**31 as you can see :)
# with $id2=2**31+1 test#8 doesn't work

#system "rm -rf $db_name";

my $writable_db;
ok( $writable_db = Search::Xapian::WritableDatabase->new( $db_name, Search::Xapian::DB_CREATE_OR_OPEN ), "Creating test db" );
my $document1;
ok($document1=Search::Xapian::Document->new(), "Creating document 1 with id [$id1]");
diag("Adding term [test1] to document 1");
$document1->add_term('test1',1);
diag("Writing document 1 to db");
$writable_db->replace_document($id1, $document1);

my $document2;
ok($document2=Search::Xapian::Document->new(), "Creating document 2 with id [$id2]");
diag("Adding term [test2] to document 2");
$document2->add_term('test2',1);
diag("Writing document 2 to db");
$writable_db->replace_document($id2, $document2);
$writable_db->flush();

my $db;
ok( $db = Search::Xapian::Database->new( $db_name ), "Opening test db" );
diag("Doc count:".$db->get_doccount);

my $query1 = Search::Xapian::Query->new('test1');
my $query2 = Search::Xapian::Query->new('test2');

my $enq1;
ok ( $enq1=$db->enquire($query1), "Searching by term [test1]");
my $matches1 = $enq1->get_mset(0,1);
is ( $matches1->size, 1, "Document found by term [test1]" );

my $enq2;
ok ( $enq2=$db->enquire($query2), "Searching by term [test2]");
my $matches2 = $enq2->get_mset(0,1) or die $!;
is ( $matches2->size, 1, "Document found by term [test2]" );
