2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 11; |
use Test::More tests => 27; |
6 |
use Test::Exception; |
use Test::Exception; |
7 |
|
use lib '.'; |
8 |
use blib; |
use blib; |
9 |
|
|
10 |
BEGIN { |
BEGIN { |
13 |
|
|
14 |
my $i; |
my $i; |
15 |
|
|
16 |
throws_ok { SWISH::PlusPlus->open() } qr/index_dir/, "need index_dir"; |
throws_ok { SWISH::PlusPlus->new() } qr/index_dir/, "need index_dir"; |
17 |
|
|
18 |
## FIXME |
## FIXME |
19 |
my $index = '/tmp/swish-pp'; |
my $index = '/tmp/swish-pp'; |
20 |
|
|
21 |
$i = SWISH::PlusPlus->open( |
$i = SWISH::PlusPlus->new( |
22 |
index_dir => $index, |
index_dir => $index, |
23 |
debug => 0, |
debug => 0, |
24 |
|
meta_in_body => 1, |
25 |
); |
); |
26 |
ok($i, "open index"); |
ok($i, "open index"); |
27 |
|
|
33 |
|
|
34 |
ok($i->index_document( 42 => 'meaning of life' ), "index 42"); |
ok($i->index_document( 42 => 'meaning of life' ), "index 42"); |
35 |
|
|
36 |
|
ok($i->add( |
37 |
|
path => 'life', |
38 |
|
title => 'Ultimate question answer found here', |
39 |
|
body => '42 is answer to all questions', |
40 |
|
meta => { |
41 |
|
author => 'Dobrica Pavlinusic', |
42 |
|
date => '2004-12-05', |
43 |
|
comment => 'woow!', |
44 |
|
}, |
45 |
|
), "index life"); |
46 |
|
|
47 |
# add one dummy document so that swish++ won't reject all words |
# add one dummy document so that swish++ won't reject all words |
48 |
# with index of just one document |
# with index of just one document |
49 |
ok($i->index_document( _dummy_ => '' ), "fillter"); |
ok($i->index_document( _dummy_ => '' ), "fillter"); |
54 |
my @r = $i->search($word); |
my @r = $i->search($word); |
55 |
cmp_ok(scalar @r, '==', 1, "find $word"); |
cmp_ok(scalar @r, '==', 1, "find $word"); |
56 |
} |
} |
57 |
|
|
58 |
|
foreach my $word (qw(Ultimate question answer found here)) { |
59 |
|
cmp_ok(scalar $i->search("title=($word)"), '==', 1, "find $word in title"); |
60 |
|
cmp_ok(scalar $i->search("$word"), '==', 1, "find $word anywhere"); |
61 |
|
} |
62 |
|
|
63 |
|
foreach my $word (qw(Dobrica Pavlinusic)) { |
64 |
|
cmp_ok(scalar $i->search("author=($word)"), '==', 1, "find $word in author"); |
65 |
|
} |
66 |
|
|
67 |
|
cmp_ok(scalar $i->search("date=2004-12-05"), '==', 1, "found date"); |
68 |
|
|
69 |
|
cmp_ok(scalar $i->search("woow!"), '==', 1, "found woow"); |
70 |
|
cmp_ok(scalar $i->search("comment=(woow)"), '==', 1, "found woow"); |