--- trunk/t/swish.t 2004/12/03 21:48:29 6 +++ trunk/t/swish.t 2004/12/05 13:30:57 11 @@ -2,8 +2,9 @@ use strict; -use Test::More tests => 7; +use Test::More tests => 27; use Test::Exception; +use lib '.'; use blib; BEGIN { @@ -12,13 +13,15 @@ my $i; -throws_ok { SWISH::PlusPlus->open() } qr/index_dir/, "need index_dir"; +throws_ok { SWISH::PlusPlus->new() } qr/index_dir/, "need index_dir"; ## FIXME my $index = '/tmp/swish-pp'; -$i = SWISH::PlusPlus->open( +$i = SWISH::PlusPlus->new( index_dir => $index, + debug => 0, + meta_in_body => 1, ); ok($i, "open index"); @@ -30,6 +33,38 @@ ok($i->index_document( 42 => 'meaning of life' ), "index 42"); +ok($i->add( + path => 'life', + title => 'Ultimate question answer found here', + body => '42 is answer to all questions', + meta => { + author => 'Dobrica Pavlinusic', + date => '2004-12-05', + comment => 'woow!', + }, +), "index life"); + # add one dummy document so that swish++ won't reject all words # with index of just one document ok($i->index_document( _dummy_ => '' ), "fillter"); + +cmp_ok($i->{'index_dir'}, 'eq', $index, "index_dir ok"); + +foreach my $word (qw(meaning of life)) { + my @r = $i->search($word); + cmp_ok(scalar @r, '==', 1, "find $word"); +} + +foreach my $word (qw(Ultimate question answer found here)) { + cmp_ok(scalar $i->search("title=($word)"), '==', 1, "find $word in title"); + cmp_ok(scalar $i->search("$word"), '==', 1, "find $word anywhere"); +} + +foreach my $word (qw(Dobrica Pavlinusic)) { + cmp_ok(scalar $i->search("author=($word)"), '==', 1, "find $word in author"); +} + +cmp_ok(scalar $i->search("date=2004-12-05"), '==', 1, "found date"); + +cmp_ok(scalar $i->search("woow!"), '==', 1, "found woow"); +cmp_ok(scalar $i->search("comment=(woow)"), '==', 1, "found woow");