Importer/Solr.pm

filter: Statementstmt 76.6% 23 / 30 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 0.0% 0 / 1 totaltotal 67.5% 27 / 40 CC 1 SCAR 2.3
CC
1
Cov
77%
_build_bag
2.0
count
2.0
__ANON__
1.1
CRAP 1.3
« Store/Solr.pm ↑ Summary Solr.pm »
1 package Catmandu::Importer::Solr;
2  
3 2 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Catmandu::Store::Solr;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Catmandu;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.0304';
9  
10 2 with 'Catmandu::Importer';
11  
12 2 has fq => (is => 'ro');
13 2 has query => (is => 'ro');
14 2 has url => (is => 'ro');
15 2 has bag => (is => 'ro');
16 0 ▶has id_field => (is => 'ro', default => sub {'_id'});
Subroutine __ANON__: not called CC=1 SCAR=1.2
17 0 ▶has bag_field => (is => 'ro', default => sub {'_bag'});
Subroutine __ANON__: not called CC=1 SCAR=1.2
18 2 has _bag => (is => 'ro', lazy => 1, builder => '_build_bag',);
19 0 ▶has fl => (is => 'ro', lazy => 1, default => sub {"*"});
Subroutine __ANON__: not called CC=1 SCAR=1.2
20  
21 0 ▶sub _build_bag {
Subroutine _build_bag: not called CC=1 SCAR=6.9
22 0 my $self = $_[0];
23 0 Catmandu::Store::Solr->new(
24 url => $self->url,
25 bag_field => $self->bag_field,
26 id_field => $self->id_field
27 )->bag($self->bag());
28 }
29  
30 sub generator {
31 my ($self) = @_;
32  
33 return sub {
34 state $start = 0;
35 state $limit = 100;
36 state $total = 100;
37 state $hits = [];
38  
39 unless (scalar(@$hits)) {
40  
41 return if $start >= $total;
42  
43 my $res = $self->_bag()->search(
44 query => $self->query,
45 fq => $self->fq,
46 start => $start,
47 limit => $limit,
48 fl => $self->fl,
49 facet => "false",
50 spellcheck => "false",
51 sort => $self->id_field() . " asc"
52 );
53 $total = $res->total;
54 $hits = $res->hits();
55  
56 $start += $limit;
57  
58 }
59  
60 shift(@$hits);
61  
62 }
63 }
64  
65 0 ▶sub count {
Subroutine count: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my ($self) = @_;
67 0 $self->_bag()->search(
68 query => $self->query,
69 fq => $self->fq,
70 limit => 0,
71 facet => "false",
72 spellcheck => "false"
73 )->total();
74 }
75  
76 =head1 NAME
77  
78 Catmandu::Importer::Solr - Catmandu module to import data from a Solr endpoint
79  
80 =head1 SYNOPSIS
81  
82 # From the command line
83 $ catmandu convert Solr --url "http://localhost:8983/solr" --query "type:book"
84  
85 # From perl
86 use Catmandu;
87  
88 my %attrs = (
89 url => "http://localhost:8983/solr",
90 query => 'type:book',
91 bag_field => '_bag',
92 id_field => '_id'
93 );
94  
95 my $importer = Catmandu->importer('Solr',%attrs);
96  
97 $importer->each(sub {
98 my $row_hash = shift;
99 ...
100 });
101  
102 =head1 AUTHOR
103  
104 Nicolas Franck, C<< nicolas.franck at ugent.be >>
105  
106 =head1 SEE ALSO
107  
108 L<Catmandu>, L<Catmandu::Importer> , L<Catmandu::Store::Solr>
109  
110 =cut
111  
112 2 1;
« Store/Solr.pm ↑ Summary Solr.pm »