2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 47; |
use Test::More tests => 56; |
6 |
use Test::Exception; |
use Test::Exception; |
7 |
use blib; |
use blib; |
8 |
|
|
16 |
|
|
17 |
## FIXME |
## FIXME |
18 |
my $index = '/tmp/swish-pp'; |
my $index = '/tmp/swish-pp'; |
19 |
|
my $debug = 0; |
20 |
|
$debug = 4 if (@ARGV); |
21 |
|
|
22 |
$i = SWISH::PlusPlus->new( |
$i = SWISH::PlusPlus->new( |
23 |
index_dir => $index, |
index_dir => $index, |
24 |
meta_in_body => 1, |
meta_in_body => 1, |
25 |
# debug => 1, |
debug => $debug, |
26 |
); |
); |
27 |
ok($i, "open index"); |
ok($i, "open index"); |
28 |
|
|
63 |
cmp_ok(scalar @r, '==', 1, "find $word"); |
cmp_ok(scalar @r, '==', 1, "find $word"); |
64 |
} |
} |
65 |
|
|
66 |
# test_find('words to test against meta','meta') |
# test_find('words to test against meta','meta', nr_results) |
67 |
sub test_find { |
sub test_find { |
68 |
my $words = shift || die "no words?"; |
my $words = shift || die "no words?"; |
69 |
my $meta = shift; |
my $meta = shift; |
70 |
|
my $nr = shift; |
71 |
|
|
72 |
|
$nr = 1 unless defined($nr); |
73 |
|
|
74 |
foreach my $word (split(/\s+/,$words)) { |
foreach my $word (split(/\s+/,$words)) { |
75 |
my $path; |
my $path; |
77 |
$q = "$meta=($word)" if ($meta); |
$q = "$meta=($word)" if ($meta); |
78 |
|
|
79 |
my @r = $i->search($q); |
my @r = $i->search($q); |
80 |
cmp_ok(scalar @r, '==', 1, "search $q"); |
cmp_ok(scalar @r, '==', $nr, "search $q - $nr results"); |
81 |
if ($meta) { |
if ($meta) { |
82 |
like($i->property(shift @r, $meta), qr/$word/i, "find $word in $meta property"); |
like($i->property(shift @r, $meta), qr/$word/i, "find $word in $meta property"); |
83 |
cmp_ok(scalar $i->search("$word"), '==', 1, "find $word anywhere"); |
cmp_ok(scalar $i->search("$word"), '==', $nr, "find $word anywhere -- $nr results"); |
84 |
} |
} |
85 |
|
|
86 |
} |
} |
92 |
test_find(( $data->{$_} || $data->{'meta'}->{$_} ), $_); |
test_find(( $data->{$_} || $data->{'meta'}->{$_} ), $_); |
93 |
} |
} |
94 |
|
|
95 |
|
ok($i->delete("life"), "delete life"); |
96 |
|
ok($i->{'_deleted'}->{'life'}, "life marked as deleted"); |
97 |
|
|
98 |
|
ok($i->finish_update, "finish_update"); |
99 |
|
|
100 |
|
test_find($data->{'body'}, undef, '0'); |