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

revision 15 by dpavlin, Sun Dec 5 15:46:10 2004 UTC revision 16 by dpavlin, Sun Dec 5 21:06:48 2004 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 29;  use Test::More tests => 47;
6  use Test::Exception;  use Test::Exception;
7  use lib '.';  use lib '.';
8  use blib;  use blib;
9    use YAML;
10    
11  BEGIN {  BEGIN {
12          use_ok('SWISH::PlusPlus')          use_ok('SWISH::PlusPlus')
# Line 20  my $index = '/tmp/swish-pp'; Line 21  my $index = '/tmp/swish-pp';
21    
22  $i = SWISH::PlusPlus->new(  $i = SWISH::PlusPlus->new(
23          index_dir => $index,          index_dir => $index,
         debug => 0,  
24          meta_in_body => 1,          meta_in_body => 1,
25    #       debug => 1,
26  );  );
27  ok($i, "open index");  ok($i, "open index");
28    
# Line 35  ok($i->{'version'}, "version ".$i->{'ver Line 36  ok($i->{'version'}, "version ".$i->{'ver
36    
37  ok($i->index_document( 42 => 'meaning of life' ), "index 42");  ok($i->index_document( 42 => 'meaning of life' ), "index 42");
38    
39  ok($i->add(  my $data = {
40          path => 'life',          path => 'life',
41          title => 'Ultimate question answer found here',          title => 'Ultimate question answer found here',
42          body => '42 is answer to all questions',          body => '42 is answer to all questions',
# Line 44  ok($i->add( Line 45  ok($i->add(
45                  date => '2004-12-05',                  date => '2004-12-05',
46                  comment => 'woow!',                  comment => 'woow!',
47          },          },
48  ), "index life");  };
49    
50    print Dump( $data );
51    
52    ok($i->add( %{$data} ), "index life");
53    
54  # add one dummy document so that swish++ won't reject all words  # add one dummy document so that swish++ won't reject all words
55  # with index of just one document  # with index of just one document
# Line 60  foreach my $word (qw(meaning of life)) { Line 65  foreach my $word (qw(meaning of life)) {
65          cmp_ok(scalar @r, '==', 1, "find $word");          cmp_ok(scalar @r, '==', 1, "find $word");
66  }  }
67    
68  foreach my $word (qw(Ultimate question answer found here)) {  # test_find('words to test against meta','meta')
69          cmp_ok(scalar $i->search("title=($word)"), '==', 1, "find $word in title");  sub test_find {
70          cmp_ok(scalar $i->search("$word"), '==', 1, "find $word anywhere");          my $words = shift || die "no words?";
71            my $meta = shift;
72    
73            foreach my $word (split(/\s+/,$words)) {
74                    my $path;
75                    my $q = $word;
76                    $q = "$meta=($word)" if ($meta);
77                    
78                    my @r = $i->search($q);
79                    cmp_ok(scalar @r, '==', 1, "search $q");
80                    if ($meta) {
81                            like($i->property(shift @r, $meta), qr/$word/i, "find $word in $meta property");
82                            cmp_ok(scalar $i->search("$word"), '==', 1, "find $word anywhere");
83                    }
84                    
85            }
86  }  }
87    
88  foreach my $word (qw(Dobrica Pavlinusic)) {  test_find($data->{'body'});
         cmp_ok(scalar $i->search("author=($word)"), '==', 1, "find $word in author");  
 }  
89    
90  cmp_ok(scalar $i->search("date=2004-12-05"), '==', 1, "found date");  foreach (qw(title author date comment)) {
91            test_find(( $data->{$_} || $data->{'meta'}->{$_} ), $_);
92    }
93    
 cmp_ok(scalar $i->search("woow!"), '==', 1, "found woow");  
 cmp_ok(scalar $i->search("comment=(woow)"), '==', 1, "found woow");  

Legend:
Removed from v.15  
changed lines
  Added in v.16

  ViewVC Help
Powered by ViewVC 1.1.26