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