line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dezi::Test::InvIndex; |
2
|
2
|
|
|
2
|
|
3087
|
use Moose; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
15
|
|
3
|
|
|
|
|
|
|
extends 'Dezi::InvIndex'; |
4
|
2
|
|
|
2
|
|
13476
|
use Types::Standard qw( InstanceOf ); |
|
2
|
|
|
|
|
66809
|
|
|
2
|
|
|
|
|
26
|
|
5
|
2
|
|
|
2
|
|
1503
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
134
|
|
6
|
2
|
|
|
2
|
|
1090
|
use Dezi::Cache; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
87
|
|
7
|
2
|
|
|
2
|
|
14
|
use Data::Dump qw( dump ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1068
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Dezi::Test::InvIndex - test in-memory invindex |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 METHODS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head2 term_cache |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 doc_cache |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 open |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 search |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 put_doc |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 get_doc |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# in memory invindex |
30
|
|
|
|
|
|
|
has 'term_cache' => ( |
31
|
|
|
|
|
|
|
is => 'rw', |
32
|
|
|
|
|
|
|
isa => InstanceOf ['Dezi::Cache'], |
33
|
|
|
|
|
|
|
default => sub { Dezi::Cache->new }, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
has 'doc_cache' => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
isa => InstanceOf ['Dezi::Cache'], |
38
|
|
|
|
|
|
|
default => sub { Dezi::Cache->new }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub open { |
42
|
0
|
|
|
0
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# no-op |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub search { |
48
|
0
|
|
|
0
|
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my ( $query, $opts ) = @_; |
50
|
0
|
0
|
|
|
|
|
if ( !defined $query ) { |
51
|
0
|
|
|
|
|
|
confess "query required"; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
my %hits; |
54
|
0
|
|
|
|
|
|
my $term_cache = $self->term_cache; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# walk the query, matching terms against our cache |
57
|
|
|
|
|
|
|
$query->walk( |
58
|
|
|
|
|
|
|
sub { |
59
|
0
|
|
|
0
|
|
|
my ( $clause, $dialect, $sub, $prefix ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#dump $clause; |
62
|
0
|
0
|
|
|
|
|
return if $clause->is_tree; # skip parents |
63
|
0
|
0
|
|
|
|
|
return unless $term_cache->has( $clause->value ); |
64
|
0
|
0
|
0
|
|
|
|
if ( $clause->op eq "" or $clause->op eq "+" ) { |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# include |
67
|
0
|
|
|
|
|
|
for my $uri ( keys %{ $term_cache->get( $clause->value ) } ) { |
|
0
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$hits{$uri}++; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# exclude |
74
|
0
|
|
|
|
|
|
for my $uri ( keys %{ $term_cache->get( $clause->value ) } ) { |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
delete $hits{$uri}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#dump \%hits; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return \%hits; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub put_doc { |
87
|
0
|
|
|
0
|
|
|
my $self = shift; |
88
|
0
|
0
|
|
|
|
|
my $doc = shift or confess "doc required"; |
89
|
0
|
|
|
|
|
|
$self->doc_cache->add( $doc->uri => $doc ); |
90
|
0
|
|
|
|
|
|
return $doc; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_doc { |
94
|
0
|
|
|
0
|
|
|
my $self = shift; |
95
|
0
|
0
|
|
|
|
|
my $uri = shift or confess "uri required"; |
96
|
0
|
|
|
|
|
|
return $self->doc_cache->get($uri); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHOR |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Peter Karman, E<lt>karpet@dezi.orgE<gt> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 BUGS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-dezi-app at rt.cpan.org>, or through |
110
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dezi-App>. |
111
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SUPPORT |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
perldoc Dezi::App |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
You can also look for information at: |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over 4 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item * Website |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L<http://dezi.org/> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * IRC |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#dezisearch at freenode |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * Mailing list |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<https://groups.google.com/forum/#!forum/dezi-search> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dezi-App> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Dezi-App> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * CPAN Ratings |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Dezi-App> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * Search CPAN |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L<https://metacpan.org/dist/Dezi-App/> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Copyright 2014 by Peter Karman |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
158
|
|
|
|
|
|
|
it under the terms of the GPL v2 or later. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L<http://dezi.org/>, L<http://swish-e.org/>, L<http://lucy.apache.org/> |
163
|
|
|
|
|
|
|
|