/[SWISH-PlusPlus]/trunk/t/01swish.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/t/01swish.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (show annotations)
Tue Dec 7 16:05:43 2004 UTC (19 years, 3 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2164 byte(s)
DEVELOPMENT STOPPED: it seems that swish++ isn't faster than swish-e if you
remove clever heuristics about english words. So, this project is abandoned.

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use Test::More tests => 56;
6 use Test::Exception;
7 use blib;
8
9 BEGIN {
10 use_ok('SWISH::PlusPlus')
11 };
12
13 my $i;
14
15 throws_ok { SWISH::PlusPlus->new() } qr/index_dir/, "need index_dir";
16
17 ## FIXME
18 my $index = '/tmp/swish-pp';
19 my $debug = 0;
20 $debug = 4 if (@ARGV);
21
22 $i = SWISH::PlusPlus->new(
23 index_dir => $index,
24 meta_in_body => 1,
25 debug => $debug,
26 );
27 ok($i, "open index");
28
29 ok(-e $index, "index exist");
30
31 ok($i->{'cwd'}, "cwd ".$i->{'cwd'});
32
33 ok($i->check_bin, "swish++ check");
34
35 ok($i->{'version'}, "version ".$i->{'version'});
36
37 ok($i->index_document( 42 => 'meaning of life' ), "index 42");
38
39 my $data = {
40 path => 'life',
41 title => 'Ultimate question answer found here',
42 body => '42 is answer to all questions',
43 meta => {
44 author => 'Dobrica Pavlinusic',
45 date => '2004-12-05',
46 comment => 'woow!',
47 },
48 };
49
50 ok($i->add( %{$data} ), "index life");
51
52 # add one dummy document so that swish++ won't reject all words
53 # with index of just one document
54 ok($i->index_document( _dummy_ => '' ), "fillter");
55
56 cmp_ok($i->{'index_dir'}, 'eq', $index, "index_dir ok");
57
58 # I would rather test search to close it itself!
59 #$i->finish_update;
60
61 foreach my $word (qw(meaning of life)) {
62 my @r = $i->search($word);
63 cmp_ok(scalar @r, '==', 1, "find $word");
64 }
65
66 # test_find('words to test against meta','meta', nr_results)
67 sub test_find {
68 my $words = shift || die "no words?";
69 my $meta = shift;
70 my $nr = shift;
71
72 $nr = 1 unless defined($nr);
73
74 foreach my $word (split(/\s+/,$words)) {
75 my $path;
76 my $q = $word;
77 $q = "$meta=($word)" if ($meta);
78
79 my @r = $i->search($q);
80 cmp_ok(scalar @r, '==', $nr, "search $q - $nr results");
81 if ($meta) {
82 like($i->property(shift @r, $meta), qr/$word/i, "find $word in $meta property");
83 cmp_ok(scalar $i->search("$word"), '==', $nr, "find $word anywhere -- $nr results");
84 }
85
86 }
87 }
88
89 test_find($data->{'body'});
90
91 foreach (qw(title author date comment)) {
92 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');

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26