line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::IndexPod; |
2
|
1
|
|
|
1
|
|
704
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
1038
|
use File::Find::Rule; |
|
1
|
|
|
|
|
9449
|
|
|
1
|
|
|
|
|
10
|
|
5
|
1
|
|
|
1
|
|
855
|
use KinoSearch; |
|
1
|
|
|
|
|
43612
|
|
|
1
|
|
|
|
|
59
|
|
6
|
1
|
|
|
1
|
|
680
|
use KinoSearch::InvIndexer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use KinoSearch::Analysis::PolyAnalyzer; |
8
|
|
|
|
|
|
|
use KinoSearch::QueryParser::QueryParser; |
9
|
|
|
|
|
|
|
use KinoSearch::Searcher; |
10
|
|
|
|
|
|
|
use Pod::Simple; |
11
|
|
|
|
|
|
|
use Pod::Simple::PullParser; |
12
|
|
|
|
|
|
|
use base qw(Class::Accessor); |
13
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw(unpacked kinosearch)); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub search { |
18
|
|
|
|
|
|
|
my ( $self, $query_string ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $analyzer |
21
|
|
|
|
|
|
|
= KinoSearch::Analysis::PolyAnalyzer->new( language => 'en' ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $query_parser = KinoSearch::QueryParser::QueryParser->new( |
24
|
|
|
|
|
|
|
analyzer => $analyzer, |
25
|
|
|
|
|
|
|
default_field => 'value', |
26
|
|
|
|
|
|
|
default_boolop => 'OR', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
my $searcher = KinoSearch::Searcher->new( |
29
|
|
|
|
|
|
|
invindex => $self->kinosearch, |
30
|
|
|
|
|
|
|
analyzer => $analyzer, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
my $query = $query_parser->parse($query_string); |
33
|
|
|
|
|
|
|
my $hits = $searcher->search( query => $query ); |
34
|
|
|
|
|
|
|
$hits->seek( 0, 1000 ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my %scores; |
37
|
|
|
|
|
|
|
while ( my $hit = $hits->fetch_hit_hashref ) { |
38
|
|
|
|
|
|
|
my $filename = $hit->{key}; |
39
|
|
|
|
|
|
|
my $score = $hit->{score}; |
40
|
|
|
|
|
|
|
$scores{$filename} = $score; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return sort { $scores{$b} <=> $scores{$a} || $a cmp $b } keys %scores; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub index { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
my $unpacked = $self->unpacked; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $analyzer |
51
|
|
|
|
|
|
|
= KinoSearch::Analysis::PolyAnalyzer->new( language => 'en' ); |
52
|
|
|
|
|
|
|
my $invindexer = KinoSearch::InvIndexer->new( |
53
|
|
|
|
|
|
|
invindex => $self->kinosearch, |
54
|
|
|
|
|
|
|
create => 1, |
55
|
|
|
|
|
|
|
analyzer => $analyzer, |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$invindexer->spec_field( name => 'key', indexed => 0, vectorized => 0 ); |
59
|
|
|
|
|
|
|
$invindexer->spec_field( name => 'value', stored => 0, vectorized => 0 ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
chdir($unpacked) || die "Could not chdir to $unpacked: $!"; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $rule = File::Find::Rule->new; |
64
|
|
|
|
|
|
|
my @files = $rule->file->in("."); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
foreach my $filename (@files) { |
67
|
|
|
|
|
|
|
next if $filename =~ /\.svn/; |
68
|
|
|
|
|
|
|
eval { |
69
|
|
|
|
|
|
|
my $parser; |
70
|
|
|
|
|
|
|
$parser = Pod::Simple::PullParser->new; |
71
|
|
|
|
|
|
|
$parser->set_source($filename); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $title = $parser->get_title; |
74
|
|
|
|
|
|
|
return unless $title; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $synopsis = $parser->_get_titled_section( |
77
|
|
|
|
|
|
|
'SYNOPSIS', |
78
|
|
|
|
|
|
|
max_token => 400, |
79
|
|
|
|
|
|
|
max_content_length => 3_000, |
80
|
|
|
|
|
|
|
desperate => 1, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $description = $parser->get_description; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $doc = $invindexer->new_doc; |
86
|
|
|
|
|
|
|
$doc->set_value( key => $filename ); |
87
|
|
|
|
|
|
|
$doc->set_value( value => "$title synopsis $description" ); |
88
|
|
|
|
|
|
|
$invindexer->add_doc($doc); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# warn "added $filename => $title synopsis $description"; |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$invindexer->finish( optimize => 1 ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |