line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dezi::InvIndex; |
2
|
10
|
|
|
10
|
|
9306
|
use Moose; |
|
10
|
|
|
|
|
480089
|
|
|
10
|
|
|
|
|
67
|
|
3
|
10
|
|
|
10
|
|
68231
|
use MooseX::StrictConstructor; |
|
10
|
|
|
|
|
80489
|
|
|
10
|
|
|
|
|
80
|
|
4
|
|
|
|
|
|
|
with 'Dezi::Role'; |
5
|
10
|
|
|
10
|
|
48559
|
use Carp; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
815
|
|
6
|
10
|
|
|
10
|
|
2075
|
use Types::Standard qw( Bool Str InstanceOf ); |
|
10
|
|
|
|
|
132778
|
|
|
10
|
|
|
|
|
117
|
|
7
|
10
|
|
|
10
|
|
16143
|
use Dezi::InvIndex::Header; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use MooseX::Types::Path::Class; |
9
|
|
|
|
|
|
|
use Class::Load (); |
10
|
|
|
|
|
|
|
use Try::Tiny; |
11
|
|
|
|
|
|
|
use overload( |
12
|
|
|
|
|
|
|
'""' => sub { shift->path }, |
13
|
|
|
|
|
|
|
'bool' => sub {1}, |
14
|
|
|
|
|
|
|
fallback => 1, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use namespace::autoclean; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.014'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $DEFAULT_NAME = 'dezi.index'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'version' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => Str, |
26
|
|
|
|
|
|
|
default => sub {$VERSION}, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'path' => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
isa => 'Path::Class::Dir', |
32
|
|
|
|
|
|
|
coerce => 1, |
33
|
|
|
|
|
|
|
default => sub { Path::Class::Dir->new($DEFAULT_NAME) } |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'clobber' => ( is => 'rw', isa => Bool, default => 0 ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
around BUILDARGS => sub { |
39
|
|
|
|
|
|
|
my $orig = shift; |
40
|
|
|
|
|
|
|
my $class = shift; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if ( @_ == 1 && !ref $_[0] ) { |
43
|
|
|
|
|
|
|
return $class->$orig( path => $_[0] ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
else { |
46
|
|
|
|
|
|
|
return $class->$orig(@_); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new_from_header { |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# open swish.xml meta file |
54
|
|
|
|
|
|
|
my $header = $self->get_header(); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# parse for index format |
57
|
|
|
|
|
|
|
my $format = $header->Index->{Format}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# create new object and re-set $self |
60
|
|
|
|
|
|
|
my $newclass = "Dezi::${format}::InvIndex"; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#warn "reblessing $self into $newclass"; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Class::Load::load_class($newclass); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return $newclass->new( |
67
|
|
|
|
|
|
|
path => $self->{path}, |
68
|
|
|
|
|
|
|
clobber => $self->{clobber}, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub open { |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if ( -d $self->path && $self->clobber ) { |
76
|
|
|
|
|
|
|
$self->path->rmtree( $self->verbose, 1 ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
elsif ( -f $self->path ) { |
79
|
|
|
|
|
|
|
confess $self->path |
80
|
|
|
|
|
|
|
. " is not a directory -- won't even attempt to clobber"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
if ( !-d $self->path ) { |
84
|
|
|
|
|
|
|
$self->warnings and Carp::cluck("no path $self->{path} -- mkpath"); |
85
|
|
|
|
|
|
|
$self->path->mkpath( $self->verbose ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub open_ro { |
92
|
|
|
|
|
|
|
shift->open(@_); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub close { 1; } |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_header { |
98
|
|
|
|
|
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
return Dezi::InvIndex::Header->new( invindex => $self ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub header_file { |
103
|
|
|
|
|
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
return $self->path->file( Dezi::InvIndex::Header->header_file ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Dezi::InvIndex - base class for Dezi inverted indexes |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SYNOPSIS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
use Dezi::InvIndex; |
120
|
|
|
|
|
|
|
my $index = Dezi::InvIndex->new(path => 'path/to/index'); |
121
|
|
|
|
|
|
|
print $index; # prints $index->path |
122
|
|
|
|
|
|
|
my $header = $index->get_header(); # $meta isa Dezi::InvIndex::Header object |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 DESCRIPTION |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
A Dezi::InvIndex is a base class for defining different inverted index formats. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 METHODS |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 new |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Constructor. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 new_from_header |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Instantiates an InvIndex object in the correct subclass |
137
|
|
|
|
|
|
|
based on the Index Format in the InvIndex header file. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Example: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my $invindex = Dezi::InvIndex->new('path/to/lucy.index'); |
142
|
|
|
|
|
|
|
# $invindex isa Dezi::Lucy::InvIndex |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 path |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns a Path::Class::Dir object representing the directory path to the index. |
147
|
|
|
|
|
|
|
The path is a directory which contains the various files that comprise the |
148
|
|
|
|
|
|
|
index. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 get_header |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Returns a Dezi::InvIndex::Header object with which you can query |
153
|
|
|
|
|
|
|
information about the index. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 header_file |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns Path::Class::File object pointing at the header_file. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 open |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Open the invindex for reading/writing. Subclasses should implement this per |
162
|
|
|
|
|
|
|
their IR library specifics. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This base open() method will rmtree( path() ) if clobber() is true, |
165
|
|
|
|
|
|
|
and will mkpath() if path() does not exist. So SUPER::open() should |
166
|
|
|
|
|
|
|
do something sane at minimum. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 open_ro |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Open the invindex in read-only mode. This is typical when searching |
171
|
|
|
|
|
|
|
the invindex. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The default open_ro() method will simply call through to open(). |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 close |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Close the index. Subclasses should implement this per |
178
|
|
|
|
|
|
|
their IR library specifics. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 clobber |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Get/set the boolean indicating whether the index should overwrite |
183
|
|
|
|
|
|
|
any existing index with the same name. The default is true. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 new_from_meta |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Returns a new instance like new() does, blessed into the appropriate |
188
|
|
|
|
|
|
|
class indicated by the C<swish.xml> meta header file. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 AUTHOR |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Peter Karman, E<lt>karpet@dezi.orgE<gt> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 BUGS |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-dezi-app at rt.cpan.org>, or through |
197
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dezi-App>. |
198
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 SUPPORT |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
perldoc Dezi::InvIndex |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
You can also look for information at: |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=over 4 |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * Website |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L<http://dezi.org/> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * IRC |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
#dezisearch at freenode |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * Mailing list |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
L<https://groups.google.com/forum/#!forum/dezi-search> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dezi-App> |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Dezi-App> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * CPAN Ratings |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Dezi-App> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item * Search CPAN |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
L<https://metacpan.org/dist/Dezi-App/> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=back |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Copyright 2014 by Peter Karman |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
245
|
|
|
|
|
|
|
it under the terms of the GPL v2 or later. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head1 SEE ALSO |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
L<http://dezi.org/>, L<http://swish-e.org/>, L<http://lucy.apache.org/> |