2 BEGIN { plan tests => 12 };
3 use Search::Xapian qw(:all);
5 my $db = Search::Xapian::WritableDatabase->new();
10 for my $q (qw( low high high )) {
11 my $doc = Search::Xapian::Document->new();
12 $doc->set_data("test t$i $q");
13 $doc->add_posting("test", 0);
14 $doc->add_posting("t$i", 1);
15 $doc->add_posting($q, 2);
16 $doc->add_value(0, $q);
17 $db->add_document($doc);
22 ok( $spy = Search::Xapian::ValueCountMatchSpy->new(0), "ValueCountMatchSpy created ok" );
25 ok( $enq = $db->enquire('test'), "db enquirable" );
27 $enq->add_matchspy($spy);
29 is( $spy->name(), "Xapian::ValueCountMatchSpy", "match spy corretly identified as Xapian::ValueCountMatchSpy" );
31 my $mset = $enq->get_mset(0, 10, 10000);
33 note $spy->get_description();
35 is( $spy->get_total(), 3, "match spy went through correct number of documents" );
38 { name => "high", freq => 2 },
39 { name => "low" , freq => 1 },
43 ok( $it = $spy->values_begin(), "values iterator properly returned from match spy" );
46 for (my $it = $spy->values_begin(); $it != $spy->values_end(); $it++) {
47 is( $it->get_termname(), $ref->[$i]->{name}, "Term iterator index $i was '" . $ref->[$i]->{name} . "' as expected" );
48 is( $it->get_termfreq(), $ref->[$i]->{freq}, "Correct frequency for index $i");
52 ok( $it = $spy->top_values_begin(1), "top values iterator properly returned from match spy" );
53 is( $it->get_termname(), $ref->[0]->{name}, "top value is indeed '" . $ref->[0]->{name} . "' as returned by top values iterator" );
55 $enq->clear_matchspies();
56 is( $spy->get_total(), 3, "clearing matchspies doesn't kill our spy reference?" );