Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/WebService/Solr/Response.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ has 'docs' =>

has 'pager' => ( is => 'rw', isa => 'Maybe[Data::Page]', lazy_build => 1 );

has 'stats' => ( is => 'rw', isa => 'Maybe[HashRef]', lazy_build => 1 );

has '_pageset_slide' =>
( is => 'rw', isa => 'Maybe[Data::Pageset]', lazy_build => 1 );
has '_pageset_fixed' =>
Expand Down Expand Up @@ -119,6 +121,13 @@ sub _build_pageset {
return $pager;
}

sub _build_stats {
my $self = shift;
my $struct = $self->content;

return $struct->{stats};
}

sub facet_counts {
return shift->content->{ facet_counts };
}
Expand Down Expand Up @@ -176,6 +185,8 @@ all responses from the service.

=item * pageset - a L<Data::Pageset> object for the search results. Takes the same arguments as C<< Data::Pageset->new >> does. All arguments optional.

=item * stats - a hashref of the SOLR statistics data if requested. (See http://wiki.apache.org/solr/StatsComponent )

=back

=head1 METHODS
Expand Down
10 changes: 8 additions & 2 deletions t/response.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use strict;
use warnings;

### XXX Whitebox tests!
use Test::More tests => 5;
use Test::More tests => 6;

use HTTP::Headers;
use HTTP::Response;
Expand All @@ -15,7 +15,7 @@ my $Class = 'WebService::Solr::Response';
my $SolrResponse = HTTP::Response->new(
200 => 'OK',
HTTP::Headers->new,
q[{"responseHeader":{"status":0,"QTime":24,"params":{"rows":"2","sort":"created_dt desc","wt":"json","start":"4","q":"foo"}},"response":{"numFound":10,"start":4,"docs":[{"name":["foo1"]},{"name":["foo2"]}]}}],
q[{"stats":{"stats_fields":{"foo1":{"min":1,"max":9}}},"responseHeader":{"status":0,"QTime":24,"params":{"rows":"2","sort":"created_dt desc","wt":"json","start":"4","q":"foo"}},"response":{"numFound":10,"start":4,"docs":[{"name":["foo1"]},{"name":["foo2"]}]}}],
);

my $Obj;
Expand Down Expand Up @@ -62,6 +62,12 @@ subtest 'Check pagers' => sub {
}
};

subtest 'Check statistics' => sub {
for my $stats ( $Obj->stats ) {
is_deeply $stats, { stats_fields => { foo1 => { min => 1, max => 9 } } };
}
};

subtest 'Special case: 0 rows' => sub {
my $http_response = HTTP::Response->new(
200 => 'OK',
Expand Down