Apache-Solr
view release on metacpan or search on metacpan
t/30result.t view on Meta::CPAN
#!/usr/bin/perl
# Test decoding the complex results
# Try all examples from http://wiki.apache.org/solr/SearchHandler
use warnings;
use strict;
use lib 'lib';
use Apache::Solr::XML;
use Test::More tests => 5;
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Quotekeys = 0;
# the server will not be called in this script.
my $server = 'http://localhost:8080/solr';
my $core = 'my-core';
my $solr = Apache::Solr::XML->new(server => $server, core => $core);
ok(defined $solr, 'instantiated client');
sub decode_xml($)
{ my $xml = shift;
my $tree = $solr->xmlsimple->XMLin($xml);
Apache::Solr::XML::_cleanup_parsed($tree);
}
### Results
my $f1 = <<'_RESULT1';
<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseHeader><status>0</status><QTime>1</QTime></responseHeader>
<result numFound="1" start="0">
<doc>
<arr name="cat"><str>electronics</str><str>hard drive</str></arr>
<arr name="features"><str>7200RPM, 8MB cache, IDE Ultra ATA-133</str><str>NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor</str></arr>
<str name="id">SP2514N</str>
<bool name="inStock">true</bool>
<str name="manu">Samsung Electronics Co. Ltd.</str>
<str name="name">Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133</str>
<int name="popularity">6</int>
<float name="price">92.0</float>
<str name="sku">SP2514N</str>
</doc>
</result>
</response>
_RESULT1
my $d1 = {
responseHeader => { status => '0', QTime => '1' },
result => {
numFound => '1',
doc => {
sku => 'SP2514N',
features => [
'7200RPM, 8MB cache, IDE Ultra ATA-133',
'NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor'
],
name => 'Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133',
manu => 'Samsung Electronics Co. Ltd.',
cat => [ 'electronics', 'hard drive' ],
popularity => '6',
price => '92.0',
id => 'SP2514N',
inStock => 1
},
start => '0'
}
};
( run in 3.171 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )