/[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

Diff of /trunk/t/01swish.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.6  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC 1.1.26