line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::Solr::Bag; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1220
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
777
|
use Catmandu::Util qw(:is); |
|
1
|
|
|
|
|
25696
|
|
|
1
|
|
|
|
|
326
|
|
5
|
1
|
|
|
1
|
|
8
|
use Carp qw(confess); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
6
|
1
|
|
|
1
|
|
416
|
use Catmandu::Hits; |
|
1
|
|
|
|
|
16894
|
|
|
1
|
|
|
|
|
49
|
|
7
|
1
|
|
|
1
|
|
711
|
use Catmandu::Store::Solr::Searcher; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
43
|
|
8
|
1
|
|
|
1
|
|
628
|
use Catmandu::Store::Solr::CQL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
9
|
1
|
|
|
1
|
|
8
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Bag'; |
12
|
|
|
|
|
|
|
with 'Catmandu::Searchable'; |
13
|
|
|
|
|
|
|
with 'Catmandu::Buffer'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub generator { |
16
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
17
|
0
|
|
|
|
|
|
my $store = $self->store; |
18
|
0
|
|
|
|
|
|
my $name = $self->name; |
19
|
0
|
|
|
|
|
|
my $limit = $self->buffer_size; |
20
|
0
|
|
|
|
|
|
my $query = qq/_bag:"$name"/; |
21
|
|
|
|
|
|
|
sub { |
22
|
0
|
|
|
0
|
|
|
state $start = 0; |
23
|
0
|
|
|
|
|
|
state $hits; |
24
|
0
|
0
|
0
|
|
|
|
unless ($hits && @$hits) { |
25
|
0
|
|
|
|
|
|
$hits = $store->solr->search($query, {start => $start, rows => $limit})->content->{response}{docs}; |
26
|
0
|
|
|
|
|
|
$start += $limit; |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
0
|
|
|
|
my $hit = shift(@$hits) || return; |
29
|
0
|
|
|
|
|
|
delete $hit->{_bag}; |
30
|
0
|
|
|
|
|
|
$hit; |
31
|
0
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub count { |
35
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
36
|
0
|
|
|
|
|
|
my $name = $self->name; |
37
|
0
|
|
|
|
|
|
my $res = $self->store->solr->search(qq/_bag:"$name"/, |
38
|
|
|
|
|
|
|
{rows => 0, facet => "false", spellcheck => "false"}); |
39
|
0
|
|
|
|
|
|
$res->content->{response}{numFound}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get { |
43
|
|
|
|
|
|
|
my ($self, $id) = @_; |
44
|
|
|
|
|
|
|
my $name = $self->name; |
45
|
|
|
|
|
|
|
my $res = $self->store->solr->search(qq/_bag:"$name" AND _id:"$id"/, |
46
|
|
|
|
|
|
|
{rows => 1, facet => "false", spellcheck => "false"}); |
47
|
|
|
|
|
|
|
my $hit = $res->content->{response}{docs}->[0] || return; |
48
|
|
|
|
|
|
|
delete $hit->{_bag}; |
49
|
|
|
|
|
|
|
$hit; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub add { |
53
|
|
|
|
|
|
|
my ($self, $data) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my @fields = (WebService::Solr::Field->new(_bag => $self->name)); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
for my $key (keys %$data) { |
58
|
|
|
|
|
|
|
my $val = $data->{$key}; |
59
|
|
|
|
|
|
|
if (is_array_ref($val)) { |
60
|
|
|
|
|
|
|
is_value($_) && push @fields, WebService::Solr::Field->new($key => $_) foreach @$val; |
61
|
|
|
|
|
|
|
} elsif (is_value($val)) { |
62
|
|
|
|
|
|
|
push @fields, WebService::Solr::Field->new($key => $val); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->buffer_add(WebService::Solr::Document->new(@fields)); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
if ($self->buffer_is_full) { |
69
|
|
|
|
|
|
|
$self->commit; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub delete { |
74
|
|
|
|
|
|
|
my ($self, $id) = @_; |
75
|
|
|
|
|
|
|
my $name = $self->name; |
76
|
|
|
|
|
|
|
$self->store->solr->delete_by_query(qq/_bag:"$name" AND _id:"$id"/); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub delete_all { |
80
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
81
|
0
|
|
|
|
|
|
my $name = $self->name; |
82
|
0
|
|
|
|
|
|
$self->store->solr->delete_by_query(qq/_bag:"$name"/); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub delete_by_query { |
86
|
|
|
|
|
|
|
my ($self, %args) = @_; |
87
|
|
|
|
|
|
|
my $name = $self->name; |
88
|
|
|
|
|
|
|
$self->store->solr->delete_by_query(qq/_bag:"$name" AND ($args{query})/); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub commit { # TODO better error handling |
92
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
93
|
0
|
|
|
|
|
|
my $solr = $self->store->solr; |
94
|
0
|
|
|
|
|
|
my $err; |
95
|
0
|
0
|
|
|
|
|
if ($self->buffer_used) { |
96
|
0
|
0
|
0
|
|
|
|
eval { $solr->add($self->buffer) } or push @{$err ||= []}, $@; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$self->clear_buffer; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
0
|
0
|
|
|
|
eval { $solr->commit } or push @{$err ||= []}, $@; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
!defined $err, $err; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub search { |
104
|
|
|
|
|
|
|
my ($self, %args) = @_; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $query = delete $args{query}; |
107
|
|
|
|
|
|
|
my $start = delete $args{start}; |
108
|
|
|
|
|
|
|
my $limit = delete $args{limit}; |
109
|
|
|
|
|
|
|
my $bag = delete $args{reify}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $name = $self->name; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if ($args{fq}) { |
114
|
|
|
|
|
|
|
$args{fq} = qq/_bag:"$name" AND ($args{fq})/; |
115
|
|
|
|
|
|
|
} else { |
116
|
|
|
|
|
|
|
$args{fq} = qq/_bag:"$name"/; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $res = $self->store->solr->search($query, {%args, start => $start, rows => $limit}); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $set = $res->content->{response}{docs}; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
if ($bag) { |
124
|
|
|
|
|
|
|
$set = [map { $bag->get($_->{_id}) } @$set]; |
125
|
|
|
|
|
|
|
} else { |
126
|
|
|
|
|
|
|
delete $_->{_bag} for @$set; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $hits = Catmandu::Hits->new({ |
130
|
|
|
|
|
|
|
limit => $limit, |
131
|
|
|
|
|
|
|
start => $start, |
132
|
|
|
|
|
|
|
total => $res->content->{response}{numFound}, |
133
|
|
|
|
|
|
|
hits => $set, |
134
|
|
|
|
|
|
|
}); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
if ($res->facet_counts) { |
137
|
|
|
|
|
|
|
$hits->{facets} = $res->facet_counts; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$hits; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub searcher { |
144
|
|
|
|
|
|
|
my ($self, %args) = @_; |
145
|
|
|
|
|
|
|
Catmandu::Store::Solr::Searcher->new(%args, bag => $self); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub translate_sru_sortkeys { |
149
|
0
|
|
|
0
|
0
|
|
confess 'TODO'; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub translate_cql_query { |
153
|
0
|
|
|
0
|
0
|
|
Catmandu::Store::Solr::CQL->parse($_[1]); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub normalize_query { |
157
|
0
|
0
|
|
0
|
0
|
|
$_[1] || "*:*"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L, L |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |