added header_first to WebPAC::Input::CSV
[webpac2] / t / 5-output-swish.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib 'lib';
5
6 use Test::More tests => 35;
7
8 BEGIN {
9         use lib 'lib';
10         use_ok( 'WebPAC::Test' );
11         use_ok( 'WebPAC::Output::SWISH' );
12         use_ok( 'SWISH::API' );
13 }
14
15 my $path = "$abs_path/kino/";
16
17 ok(my $out = new WebPAC::Output::SWISH({
18         database => 'test',
19         %LOG
20 }), "new");
21
22 ok( $out->init, 'init' );
23
24 my $ds = {
25         'Source' => {
26                 'name' => 'Izvor: ',
27                 'search' => [ 'tko zna' ]
28         },
29         'ID' => {
30                 'search' => [ 'id' ],
31         },
32         'Array' => {
33                 'search' => [ qw/a1 a2 s3 a4 a5/ ],
34         },
35         'foo' => {
36                 'search' => [ 'foo' ],
37         },
38 };
39
40 ok( $out->add( 42, $ds ), 'add 42' );
41
42 my @strange = ( qw/èajðinica odma¹æivanje ¾abokreèina ¹uma/ );
43
44 ok( $out->add( 99, { foo => { search => [ @strange ] } } ), 'add 99' );
45
46 ok( $out->add( 100, { foo => { search => [ qw/foo bar baz/ ] } } ), 'add 100' );
47
48 ok( $out->finish, 'finish' );
49
50 sub test_search {
51         my ( $query_string, $expected_hits ) = @_;
52
53         my $swish = SWISH::API->new( $out->index_path );
54         $swish->abort_last_error if $swish->Error;
55
56         my $results = $swish->query( $query_string );
57
58         my $total_hits = $results->hits;
59
60         ok( $total_hits, "search '$query_string'" );
61
62         diag "Total hits: $total_hits\n" if $debug;
63
64         cmp_ok( $total_hits, '==', $expected_hits, 'total_hits' );
65
66         while ( my $hit = $results->next_result ) {
67                 diag dump($hit) if $debug;
68         }
69
70 }
71
72 test_search( 'foo', 2 );
73
74 test_search( $_, 1 ) foreach @strange;
75