Compat/Util.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 35 CC 3 SCAR 19.5
CC
3
Cov
0%
filter_keywords
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1 package Search::Elasticsearch::Compat::Util;
2 $Search::Elasticsearch::Compat::Util::VERSION = '0.10';
3 use strict;
4 use warnings;
5 use Sub::Exporter -setup => { exports => ['filter_keywords'] };
6  
7 #===================================
8 sub filter_keywords {
9 #===================================
10 local $_ = shift;
11  
12 s{[^[:alpha:][:digit:] \-+'"*@\._]+}{ }g;
13  
14 return '' unless /[[:alpha:][:digit:]]/;
15  
16 s/\s*\b(?:and|or|not)\b\s*/ /gi;
17  
18 # remove '-' that don't have spaces before them
19 s/(?<! )-/\ /g;
20  
21 # remove the spaces after a + or -
22 s/([+-])\s+/$1/g;
23  
24 # remove + or - not followed by a letter, number or "
25 s/[+-](?![[:alpha:][:digit:]"])/ /g;
26  
27 # remove * without 3 char prefix
28 s/(?<![[:alpha:][:digit:]\-@\._]{3})\*/ /g;
29  
30 my $quotes = (tr/"//);
31 if ( $quotes % 2 ) { $_ .= '"' }
32  
33 s/^\s+//;
34 s/\s+$//;
35  
36 return $_;
37 }
38  
39 # ABSTRACT: Provides the filter_keywords utility
40  
41  
42 1;
43  
44 __END__