blib/lib/Dancer/Plugin/Lucy.pm untested

filter: Statementstmt 0.0% 0 / 43 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 totaltotal 0.0% 0 / 57 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # ABSTRACT: Lucy interface for Dancer applications
2  
3 use strict;
4 use warnings;
5 package Dancer::Plugin::Lucy;
6 use Dancer ':syntax';
7 use Dancer::Plugin;
8  
9 use Lucy::Index::Indexer;
10 use Lucy::Plan::Schema;
11 use Lucy::Plan::FullTextType;
12 use Lucy::Analysis::PolyAnalyzer;
13  
14 use Lucy::Search::IndexSearcher;
15  
16 register indexer => sub {
17 my $conf = plugin_setting();
18 my $schema = Lucy::Plan::Schema->new();
19  
20 my $polyanalyser = Lucy::Analysis::PolyAnalyzer->new(
21 language => $conf->{polyanalyser}{language},
22 );
23  
24 my $type = Lucy::Plan::FullTextType->new(
25 analyzer => $polyanalyser,
26 );
27  
28 foreach my $field ( @{ $conf->{schema}{fields}} ) {
29 $schema->spec_field( name => $field, type => $type );
30 }
31  
32 my $indexer = Lucy::Index::Indexer->new(
33 schema => $schema,
34 index => $conf->{index},
35 create => $conf->{create} || 0,
36 truncate => $conf->{truncate} || 0,
37 );
38  
39 return $indexer;
40 };
41  
42 register searcher => sub {
43 my $conf = plugin_setting();
44 my $searcher = Lucy::Search::IndexSearcher->new(
45 index => $conf->{index},
46 );
47  
48 return $searcher;
49 };
50  
51 register_plugin;
52  
53 1;
54  
55 __END__