line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::Lucy; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
79743
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
154287
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
248
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
721
|
use Lucy::Plan::Schema; |
|
1
|
|
|
|
|
18953
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
361
|
use Lucy::Plan::StringType; |
|
1
|
|
|
|
|
114
|
|
|
1
|
|
|
|
|
28
|
|
7
|
1
|
|
|
1
|
|
325
|
use Lucy::Plan::FullTextType; |
|
1
|
|
|
|
|
143
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
347
|
use Lucy::Analysis::PolyAnalyzer; |
|
1
|
|
|
|
|
111
|
|
|
1
|
|
|
|
|
28
|
|
9
|
1
|
|
|
1
|
|
346
|
use Lucy::Index::Indexer; |
|
1
|
|
|
|
|
108
|
|
|
1
|
|
|
|
|
26
|
|
10
|
1
|
|
|
1
|
|
342
|
use Lucy::Search::IndexSearcher; |
|
1
|
|
|
|
|
115
|
|
|
1
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
349
|
use Data::MessagePack; |
|
1
|
|
|
|
|
881
|
|
|
1
|
|
|
|
|
22
|
|
12
|
1
|
|
|
1
|
|
421
|
use Catmandu::Store::Lucy::Bag; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
526
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Catmandu::Store'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Catmandu::Store::Lucy - A searchable store backed by Lucy |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Version 0.0101 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '0.0104'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# From the command line |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$ catmandu import JSON to Lucy --path /path/to/index/ < data.json |
33
|
|
|
|
|
|
|
$ catmandu export Lucy --path /path/to/index/ to JSON > data.json |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# From perl |
36
|
|
|
|
|
|
|
use Catmandu; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $store = Catmandu->store('Lucy',path => '/path/to/index/'); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $book = $store->bag->add({ title => 'Advanced Perl' }); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
printf "book stored as %s\n", $book->{_id}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$store->bag->commit; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$bag->get($id); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# all bags are iterators |
49
|
|
|
|
|
|
|
$bag->each(sub { ... }); |
50
|
|
|
|
|
|
|
$bag->take(10)->each(sub { ... }); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $hits = $bag->search(query => 'perl'); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# hits is an iterator |
55
|
|
|
|
|
|
|
$hits->each(sub { |
56
|
|
|
|
|
|
|
say $_[0]->{title}; |
57
|
|
|
|
|
|
|
}); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$bag->delete($id); |
60
|
|
|
|
|
|
|
$bag->delete_by_query(query => 'perl'); |
61
|
|
|
|
|
|
|
$bag->delete_all; |
62
|
|
|
|
|
|
|
$bag->commit; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
has path => (is => 'ro', required => 1); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
for my $attr (qw(analyzer ft_field_type schema)) { |
69
|
|
|
|
|
|
|
has "_$attr" => (is => 'ro', lazy => 1, builder => "_build_$attr"); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
for my $attr (qw(indexer searcher)) { |
73
|
|
|
|
|
|
|
has "_$attr" => (is => 'ro', lazy => 1, builder => "_build_$attr", clearer => 1, predicate => 1); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
8
|
|
|
8
|
|
132
|
sub _messagepack { state $_messagepack = Data::MessagePack->new->utf8 } |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _build_analyzer { |
79
|
1
|
|
|
1
|
|
54
|
Lucy::Analysis::PolyAnalyzer->new(language => 'en'); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _build_ft_field_type { |
83
|
1
|
|
|
1
|
|
10
|
my $self = $_[0]; |
84
|
1
|
|
|
|
|
16
|
Lucy::Plan::FullTextType->new(analyzer => $self->_analyzer, stored => 0); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _build_schema { |
88
|
1
|
|
|
1
|
|
10
|
my $self = $_[0]; |
89
|
1
|
|
|
|
|
23
|
my $schema = Lucy::Plan::Schema->new; |
90
|
1
|
|
|
|
|
28
|
$schema->spec_field(name => '_id', type => Lucy::Plan::StringType->new(stored => 1, sortable => 1)); |
91
|
1
|
|
|
|
|
8
|
$schema->spec_field(name => '_bag', type => Lucy::Plan::StringType->new(stored => 0)); |
92
|
1
|
|
|
|
|
17
|
$schema->spec_field(name => '_data', type => Lucy::Plan::BlobType->new(stored => 1)); |
93
|
1
|
|
|
|
|
4
|
$schema; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _build_indexer { |
97
|
4
|
|
|
4
|
|
35
|
my $self = $_[0]; |
98
|
4
|
|
|
|
|
54
|
Lucy::Index::Indexer->new(schema => $self->_schema, index => $self->path, create => 1); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _build_searcher { |
102
|
5
|
|
|
5
|
|
43
|
my $self = $_[0]; |
103
|
5
|
|
|
|
|
52
|
Lucy::Search::IndexSearcher->new(index => $self->path); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _commit { |
107
|
4
|
|
|
4
|
|
7
|
my ($self) = @_; |
108
|
|
|
|
|
|
|
|
109
|
4
|
50
|
|
|
|
17
|
if ($self->_has_indexer) { |
110
|
4
|
|
|
|
|
56
|
$self->_indexer->commit; |
111
|
4
|
|
|
|
|
13338
|
$self->_clear_indexer; |
112
|
4
|
|
|
|
|
320
|
$self->_clear_searcher; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SEE ALSO |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L<Catmandu::Store> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Nicolas Steenlant, C<< <nicolas.steenlant at ugent.be> >> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
127
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
128
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |