--- trunk/t/01swish.t 2004/12/05 15:46:10 15 +++ trunk/t/01swish.t 2004/12/05 21:06:48 16 @@ -2,10 +2,11 @@ use strict; -use Test::More tests => 29; +use Test::More tests => 47; use Test::Exception; use lib '.'; use blib; +use YAML; BEGIN { use_ok('SWISH::PlusPlus') @@ -20,8 +21,8 @@ $i = SWISH::PlusPlus->new( index_dir => $index, - debug => 0, meta_in_body => 1, +# debug => 1, ); ok($i, "open index"); @@ -35,7 +36,7 @@ ok($i->index_document( 42 => 'meaning of life' ), "index 42"); -ok($i->add( +my $data = { path => 'life', title => 'Ultimate question answer found here', body => '42 is answer to all questions', @@ -44,7 +45,11 @@ date => '2004-12-05', comment => 'woow!', }, -), "index life"); +}; + +print Dump( $data ); + +ok($i->add( %{$data} ), "index life"); # add one dummy document so that swish++ won't reject all words # with index of just one document @@ -60,16 +65,29 @@ 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"); +# test_find('words to test against meta','meta') +sub test_find { + my $words = shift || die "no words?"; + my $meta = shift; + + foreach my $word (split(/\s+/,$words)) { + my $path; + my $q = $word; + $q = "$meta=($word)" if ($meta); + + my @r = $i->search($q); + cmp_ok(scalar @r, '==', 1, "search $q"); + if ($meta) { + like($i->property(shift @r, $meta), qr/$word/i, "find $word in $meta property"); + 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"); -} +test_find($data->{'body'}); -cmp_ok(scalar $i->search("date=2004-12-05"), '==', 1, "found date"); +foreach (qw(title author date comment)) { + test_find(( $data->{$_} || $data->{'meta'}->{$_} ), $_); +} -cmp_ok(scalar $i->search("woow!"), '==', 1, "found woow"); -cmp_ok(scalar $i->search("comment=(woow)"), '==', 1, "found woow");