Plugin/Search/Indexer.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Plugin/ImageResize.pm ↑ Summary Plugin/ImageGallery.pm »
1 package App::ZofCMS::Plugin::Search::Indexer;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our $VERSION = '1.001003'; # VERSION
7  
8 1 ▶use base 'App::ZofCMS::Plugin::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 0 ▶use Search::Indexer;
Subroutine BEGIN: called CC=1 SCAR=2.6
10  
11 sub _key { 'plug_search_indexer' }
12 sub _defaults {
13 return (
14 dir => 'index_files',
15 cell => 'd',
16 key => 'search_indexer',
17 obj_args => [],
18 exact_match => 0,
19 # add => {},
20 # remove => [],
21 # search => '' || [],
22 );
23 }
24 sub _do {
25 my ( $self, $conf, $t, $q, $config ) = @_;
26  
27 return
28 unless defined $conf->{add}
29 or defined $conf->{remove}
30 or defined $conf->{search};
31  
32 my $ix = Search::Indexer->new(
33 dir => $conf->{dir},
34 (
35 writeMode => ( defined $conf->{add} or defined $conf->{remove} )
36 ? 1 : 0
37 ),
38 @{ $conf->{obj_args} || [] }
39 );
40  
41 if ( defined $conf->{remove} ) {
42 $conf->{remove} = [ $conf->{remove} ]
43 unless ref $conf->{remove};
44  
45 if ( ref $conf->{remove} eq 'HASH' ) {
46 for ( keys %{ $conf->{remove} || {} } ) {
47 $ix->remove( $_, $conf->{remove}{ $_ } );
48 }
49 }
50 else {
51 for ( @{ $conf->{remove} || [] } ) {
52 $ix->remove( $_ );
53 }
54 }
55 }
56  
57 for ( keys %{ $conf->{add} || {} } ) {
58 $ix->add( $_, $conf->{add}{ $_ } );
59 }
60  
61 if ( defined $conf->{search} ) {
62 do_search( $conf, $t, $ix );
63 }
64 }
65  
66 sub do_search {
67 my ( $conf, $t, $ix ) = @_;
68 my $search = $conf->{search};
69  
70 if ( ref $search ) {
71 for ( @$search ) {
72 push @{ $t->{ $conf->{cell} }{ $conf->{key} } },
73 $ix->search( $_, $conf->{exact_match} );
74 }
75 }
76 else {
77 $t->{ $conf->{cell} }{ $conf->{key} } = $ix->search( $search, $conf->{exact_match} );
78 }
79 }
80  
81 1;
82 __END__
« Plugin/ImageResize.pm ↑ Summary Plugin/ImageGallery.pm »