Apache-Solr

 view release on metacpan or  search on metacpan

t/21json.t  view on Meta::CPAN


ok(defined $r1, 'lookup search results for "id"');
isa_ok($r1, 'ARRAY');
cmp_ok(scalar @$r1, '==', 2, 'both documents have an id');
isa_ok($r1->[0], 'ARRAY', 'is array of arrays');
cmp_ok(scalar @{$r1->[0]}, '==', 2, 'each size 2');
cmp_ok(scalar @{$r1->[1]}, '==', 2, 'each size 2');

### test $solr->select with one result

my $t2 = $solr->select(q => 'text:tic', hl => {fl => 'content'});
#warn Dumper $t2->decoded;
isa_ok($t2, 'Apache::Solr::Result');
ok($t2, 'select was successful');
is($t2->endpoint, "$server/select?wt=$format&q=text%3Atic&hl=true&hl.fl=content");

cmp_ok($t2->nrSelected, '==', 1);

my $d2 = $t2->selected(0);
#warn Dumper $d2;
isa_ok($d2, 'Apache::Solr::Document', 'got 1 answer');
isa_ok($d2->field('subject'), 'HASH', 'subject');
is($d2->field('subject')->{content}, '1 2 3');
is($d2->content('subject'), '1 2 3');
is($d2->_subject, '1 2 3');

#ok($d2->{hl}, 'got 1 hightlights');

### test $solr->select with two results

my $t3 = $solr->select(q => 'text:tac', rows => 1, hl => {fl => 'content'});
ok($t3, 'select was successful');
isa_ok($t3, 'Apache::Solr::Result');
is($t3->endpoint, "$server/select?wt=$format&q=text%3Atac&rows=1&hl=true&hl.fl=content");

cmp_ok($t3->nrSelected, '==', 2, '2 items selected');

cmp_ok($t3->fullPageSize, '==', 1, 'page size 1');
cmp_ok($t3->selectedPageNr(0), '==', 0, 'item 0 on page 0');
cmp_ok($t3->selectedPageNr(1), '==', 1, 'item 1 on page 1');

my $d3a = $t3->selected(0);
is($d3a->rank, 0, 'rank 0');
#warn Dumper $d3a;
my %id3 = ($d3a->uniqueId => $d3a);
isa_ok($d3a, 'Apache::Solr::Document', 'got 1 doc answer');

my $d3b = $t3->selected(1);
is($d3b->rank, 1, 'rank 1');
#warn Dumper $d3b;
isa_ok($d3b, 'Apache::Solr::Document', 'got 2 answer');
$id3{$d3b->uniqueId} = $d3b;
cmp_ok(keys %id3, '==', 2, 'both documents found');
ok($id3{A}, 'found id=A');
ok($id3{B}, 'found id=B');

my $h3a = $t3->highlighted($id3{A});
isa_ok($h3a, 'Apache::Solr::Document', 'got 1 hl answer');
is($h3a->_content, '<html>tic <em>tac</em>', 'test hl content');

### upload document

#my $t4 = $solr->extractDocument( #overwrite => 1, commit => 1
#   extractOnly => 1, file => 't/a.pdf');
my $t4 = $solr->extractDocument(overwrite => 1, commit => 1,
   literal_id => 'C', file => 't/a.pdf');
ok($t4, 'uploaded document 3, an pdf');

done_testing;



( run in 1.436 second using v1.01-cache-2.11-cpan-b16cb0d3907 )