line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Hits; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
104279
|
use Catmandu::Sane; |
|
18
|
|
|
|
|
56
|
|
|
18
|
|
|
|
|
225
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
18
|
|
|
18
|
|
165
|
use Moo; |
|
18
|
|
|
|
|
48
|
|
|
18
|
|
|
|
|
95
|
|
8
|
18
|
|
|
18
|
|
6623
|
use namespace::clean; |
|
18
|
|
|
|
|
44
|
|
|
18
|
|
|
|
|
425
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has start => (is => 'ro', required => 1); |
11
|
|
|
|
|
|
|
has limit => (is => 'ro', required => 1); |
12
|
|
|
|
|
|
|
has total => (is => 'ro', required => 1); |
13
|
|
|
|
|
|
|
has hits => (is => 'ro', required => 1); |
14
|
|
|
|
|
|
|
has maximum_offset => (is => 'ro'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
with 'Catmandu::Iterable'; |
17
|
|
|
|
|
|
|
with 'Catmandu::Paged'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub size { |
20
|
1
|
|
|
1
|
0
|
3
|
scalar @{$_[0]->hits}; |
|
1
|
|
|
|
|
8
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub more { |
24
|
1
|
|
|
1
|
1
|
11080
|
my $self = $_[0]; |
25
|
1
|
|
|
|
|
5
|
my $start = $self->start; |
26
|
1
|
|
|
|
|
4
|
my $limit = $self->limit; |
27
|
1
|
|
|
|
|
3
|
my $max_offset = $self->maximum_offset; |
28
|
1
|
50
|
33
|
|
|
5
|
return 0 if $max_offset && $start + $limit > $max_offset; |
29
|
1
|
|
|
|
|
7
|
$start + $limit < $self->total; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub generator { |
33
|
1
|
|
|
1
|
0
|
4
|
my $self = $_[0]; |
34
|
1
|
|
|
|
|
4
|
my $hits = $self->hits; |
35
|
1
|
|
|
|
|
2
|
my $i = 0; |
36
|
|
|
|
|
|
|
sub { |
37
|
1
|
|
|
1
|
|
5
|
$hits->[$i++]; |
38
|
1
|
|
|
|
|
7
|
}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub to_array { |
42
|
6
|
|
|
6
|
0
|
11
|
[@{$_[0]->hits}]; |
|
6
|
|
|
|
|
136
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub count { |
46
|
1
|
|
|
1
|
0
|
2
|
scalar @{$_[0]->hits}; |
|
1
|
|
|
|
|
4
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub each { |
50
|
1
|
|
|
1
|
0
|
2
|
my ($self, $cb) = @_; |
51
|
1
|
|
|
|
|
5
|
my $hits = $self->hits; |
52
|
1
|
|
|
|
|
3
|
for my $hit (@$hits) { |
53
|
100
|
|
|
|
|
233
|
$cb->($hit); |
54
|
|
|
|
|
|
|
} |
55
|
1
|
|
|
|
|
6
|
$self->count; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub first { |
59
|
1
|
|
|
1
|
0
|
7
|
$_[0]->hits->[0]; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=pod |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Catmandu::Hits - Iterable object that wraps Catmandu::Store search hits |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SYNOPSIS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $store = Catmandu::Store::Solr->new; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $hits = $store->bag->search( |
77
|
|
|
|
|
|
|
query => 'dna' , |
78
|
|
|
|
|
|
|
start => 0 , |
79
|
|
|
|
|
|
|
limit => 100 , |
80
|
|
|
|
|
|
|
sort => 'title desc', |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Every hits is an iterator... |
84
|
|
|
|
|
|
|
$hits->each(sub { ... }); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
printf "Found %s $hits\n" , $hits->total; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $start = $hits->start; |
89
|
|
|
|
|
|
|
my $limit = $hits->limit; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $prev = $hits->previous_page; |
92
|
|
|
|
|
|
|
my $next = $hits->next_page; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 METHODS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
A Catmandu::Hits object provides the following methods in addition to |
97
|
|
|
|
|
|
|
methods of L<Catmandu::Iterable> and L<Catmandu::Paged>. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 total |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns the total number of hits matching the query. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 start |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Returns the start index for the search results. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 limit |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Returns the maximum number of search results returned. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 more |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Return true if there are more search results. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 SEE ALSO |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
L<Catmandu::Bag>, L<Catmandu::Searchable>, L<Catmandu::Store> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |