| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Catmandu::Store::Lucy; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 76081 | use Catmandu::Sane; | 
|  | 1 |  |  |  |  | 119678 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 4 | 1 |  |  | 1 |  | 261 | use Moo; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 5 | 1 |  |  | 1 |  | 696 | use Lucy::Plan::Schema; | 
|  | 1 |  |  |  |  | 16872 |  | 
|  | 1 |  |  |  |  | 31 |  | 
| 6 | 1 |  |  | 1 |  | 392 | use Lucy::Plan::StringType; | 
|  | 1 |  |  |  |  | 96 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 7 | 1 |  |  | 1 |  | 332 | use Lucy::Plan::FullTextType; | 
|  | 1 |  |  |  |  | 120 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 8 | 1 |  |  | 1 |  | 330 | use Lucy::Analysis::PolyAnalyzer; | 
|  | 1 |  |  |  |  | 95 |  | 
|  | 1 |  |  |  |  | 73 |  | 
| 9 | 1 |  |  | 1 |  | 333 | use Lucy::Index::Indexer; | 
|  | 1 |  |  |  |  | 122 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 10 | 1 |  |  | 1 |  | 330 | use Lucy::Search::IndexSearcher; | 
|  | 1 |  |  |  |  | 95 |  | 
|  | 1 |  |  |  |  | 27 |  | 
| 11 | 1 |  |  | 1 |  | 333 | use Data::MessagePack; | 
|  | 1 |  |  |  |  | 829 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 12 | 1 |  |  | 1 |  | 416 | use Catmandu::Store::Lucy::Bag; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 484 |  | 
| 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.0103'; | 
| 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 |  | 138 | sub _messagepack { state $_messagepack = Data::MessagePack->new->utf8 } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | sub _build_analyzer { | 
| 79 | 1 |  |  | 1 |  | 51 | Lucy::Analysis::PolyAnalyzer->new(language => 'en'); | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | sub _build_ft_field_type { | 
| 83 | 1 |  |  | 1 |  | 9 | my $self = $_[0]; | 
| 84 | 1 |  |  |  |  | 14 | Lucy::Plan::FullTextType->new(analyzer => $self->_analyzer, stored => 0); | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub _build_schema { | 
| 88 | 1 |  |  | 1 |  | 9 | my $self = $_[0]; | 
| 89 | 1 |  |  |  |  | 17 | my $schema = Lucy::Plan::Schema->new; | 
| 90 | 1 |  |  |  |  | 19 | $schema->spec_field(name => '_id',   type => Lucy::Plan::StringType->new(stored => 1, sortable => 1)); | 
| 91 | 1 |  |  |  |  | 14 | $schema->spec_field(name => '_bag',  type => Lucy::Plan::StringType->new(stored => 0)); | 
| 92 | 1 |  |  |  |  | 11 | $schema->spec_field(name => '_data', type => Lucy::Plan::BlobType->new(stored => 1)); | 
| 93 | 1 |  |  |  |  | 5 | $schema; | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub _build_indexer { | 
| 97 | 4 |  |  | 4 |  | 23 | my $self = $_[0]; | 
| 98 | 4 |  |  |  |  | 58 | Lucy::Index::Indexer->new(schema => $self->_schema, index => $self->path, create => 1); | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | sub _build_searcher { | 
| 102 | 5 |  |  | 5 |  | 29 | my $self = $_[0]; | 
| 103 | 5 |  |  |  |  | 58 | Lucy::Search::IndexSearcher->new(index => $self->path); | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | sub _commit { | 
| 107 | 4 |  |  | 4 |  | 5 | my ($self) = @_; | 
| 108 |  |  |  |  |  |  |  | 
| 109 | 4 | 50 |  |  |  | 15 | if ($self->_has_indexer) { | 
| 110 | 4 |  |  |  |  | 51 | $self->_indexer->commit; | 
| 111 | 4 |  |  |  |  | 13846 | $self->_clear_indexer; | 
| 112 | 4 |  |  |  |  | 288 | $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; |