File: collapse.t

package info (click to toggle)
libsearch-xapian-perl 1.2.25.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: perl: 2,332; makefile: 6
file content (65 lines) | stat: -rw-r--r-- 1,599 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use strict;
# Before 'make install' is performed this script should be runnable with
# 'make test'. After 'make install' it should work as 'perl test.pl'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';

# Make warnings fatal
use warnings;
BEGIN {$SIG{__WARN__} = sub { die "Terminating test due to warning: $_[0]" } };

use Test::More;
BEGIN { plan tests => 8 };
use Search::Xapian qw(:all);

#########################

# Insert your test code below, the Test module is use()ed here so read
# its man page ( perldoc Test ) for help writing this test script.

sub mset_expect_order (\@@) {
    my ($m, @a) = @_;
    my @m = map { $_->get_docid() } @{$m};
    is( scalar @m, scalar @a );
    for my $j (0 .. (scalar @a - 1)) {
	is( $m[$j], $a[$j] );
    }
}

my $db;
ok( $db = Search::Xapian::WritableDatabase->new(), "test db opened ok" );

my $enquire;
ok( $enquire = Search::Xapian::Enquire->new( $db ), "enquire object created" );

my $doc;
ok( $doc = Search::Xapian::Document->new() );
$doc->add_value(0, "A");
$doc->add_term("foo");
$db->add_document($doc);
$doc->add_term("foo");
$db->add_document($doc);
$doc->add_term("foo");
$db->add_document($doc);
$doc->add_term("foo");
$db->add_document($doc);
$doc->add_term("foo");
$db->add_document($doc);

$enquire->set_query(Search::Xapian::Query->new("foo"));

{
    $enquire->set_collapse_key(0);
    my @matches = $enquire->matches(0, 3);
    mset_expect_order(@matches, (5));
}

{
    $enquire->set_collapse_key(0, 2);
    my @matches = $enquire->matches(0, 3);
    mset_expect_order(@matches, (5, 4));
}

1;