line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::Solr; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
2800
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
163570
|
|
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
937
|
use Catmandu::Store::Solr; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
55
|
|
5
|
2
|
|
|
2
|
|
11
|
use Catmandu; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
18
|
|
6
|
2
|
|
|
2
|
|
485
|
use Moo; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.0304'; |
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 => (is => 'ro', lazy => 1, builder => '_build_bag',); |
19
|
|
|
|
|
|
|
has fl => (is => 'ro', lazy => 1, default => sub {"*"}); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _build_bag { |
22
|
0
|
|
|
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
|
|
|
|
|
|
|
sub count { |
66
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
1; |