2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 4; |
use Test::More tests => 22; |
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->new() } qr/index/, "need index"; |
throws_ok { SWISH::PlusPlus->open() } qr/index_dir/, "need index_dir"; |
17 |
|
|
18 |
## FIXME |
## FIXME |
19 |
my $index = '/tmp/swish-pp'; |
my $index = '/tmp/swish-pp'; |
20 |
|
|
21 |
ok($i = new SWISH::PlusPlus( index=> $index ), "new"); |
$i = SWISH::PlusPlus->open( |
22 |
|
index_dir => $index, |
23 |
|
debug => 0, |
24 |
|
meta_in_body => 1, |
25 |
|
); |
26 |
|
ok($i, "open index"); |
27 |
|
|
28 |
ok(-e $index, "index exist"); |
ok(-e $index, "index exist"); |
29 |
|
|
30 |
|
ok($i->check_bin, "swish++ check"); |
31 |
|
|
32 |
|
diag $i->{'version'} || die; |
33 |
|
|
34 |
|
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 |
|
), "index life"); |
41 |
|
|
42 |
|
# add one dummy document so that swish++ won't reject all words |
43 |
|
# with index of just one document |
44 |
|
ok($i->index_document( _dummy_ => '' ), "fillter"); |
45 |
|
|
46 |
|
cmp_ok($i->{'index_dir'}, 'eq', $index, "index_dir ok"); |
47 |
|
|
48 |
|
foreach my $word (qw(meaning of life)) { |
49 |
|
my @r = $i->search($word); |
50 |
|
cmp_ok(scalar @r, '==', 1, "find $word"); |
51 |
|
} |
52 |
|
|
53 |
|
foreach my $word (qw(Ultimate question answer found here)) { |
54 |
|
cmp_ok(scalar $i->search("title=($word)"), '==', 1, "find $word in title"); |
55 |
|
cmp_ok(scalar $i->search("$word"), '==', 1, "find $word anywhere"); |
56 |
|
} |