line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ElasticSearchX::Autocomplete; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
31670
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
112
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
8
|
1
|
|
|
1
|
|
388
|
use ElasticSearch 0.52; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use ElasticSearchX::Autocomplete::Util qw(_create_accessors _params ); |
10
|
|
|
|
|
|
|
use ElasticSearchX::Autocomplete::Type(); |
11
|
|
|
|
|
|
|
use JSON(); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $JSON = JSON->new()->utf8(1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->_create_accessors( |
16
|
|
|
|
|
|
|
['cache'], |
17
|
|
|
|
|
|
|
['debug'], |
18
|
|
|
|
|
|
|
['JSON'], |
19
|
|
|
|
|
|
|
[ 'es', q(croak "Missing required param 'es'") ], |
20
|
|
|
|
|
|
|
[ 'index', q(croak "Missing required param 'index'") ], |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#=================================== |
25
|
|
|
|
|
|
|
sub new { |
26
|
|
|
|
|
|
|
#=================================== |
27
|
|
|
|
|
|
|
my ( $proto, $params ) = _params(@_); |
28
|
|
|
|
|
|
|
my $class = ref $proto || $proto; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $self = { _debug => 0, _types => {}, _JSON => $JSON }; |
31
|
|
|
|
|
|
|
bless $self, $class; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $types = delete $params->{types} || {}; |
34
|
|
|
|
|
|
|
$self->$_( $params->{$_} ) for keys %$params; |
35
|
|
|
|
|
|
|
$self->add_type( $_, $types->{$_} ) for keys %$types; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#=================================== |
41
|
|
|
|
|
|
|
sub types { shift->{_types} } |
42
|
|
|
|
|
|
|
#=================================== |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#=================================== |
45
|
|
|
|
|
|
|
sub type { |
46
|
|
|
|
|
|
|
#=================================== |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
my $type = shift or croak "No type name passed to type()"; |
49
|
|
|
|
|
|
|
return $self->{_types}{$type} || croak "Unknown type '$type'"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#=================================== |
53
|
|
|
|
|
|
|
sub add_type { |
54
|
|
|
|
|
|
|
#=================================== |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
my $name = shift; |
57
|
|
|
|
|
|
|
my $defn = shift || {}; |
58
|
|
|
|
|
|
|
my $type = ElasticSearchX::Autocomplete::Type->new( |
59
|
|
|
|
|
|
|
name => $name, |
60
|
|
|
|
|
|
|
( map { $_ => $self->$_ } qw(es index cache JSON debug) ), %$defn |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
return $self->{_types}{$name} = $type; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#=================================== |
66
|
|
|
|
|
|
|
sub indexer { |
67
|
|
|
|
|
|
|
#=================================== |
68
|
|
|
|
|
|
|
my ( $self, $params ) = _params(@_); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
require ElasticSearchX::Autocomplete::Indexer; |
71
|
|
|
|
|
|
|
return ElasticSearchX::Autocomplete::Indexer->new( |
72
|
|
|
|
|
|
|
alias => $self->index, |
73
|
|
|
|
|
|
|
( map { $_ => $self->$_ } qw(es debug types JSON) ), |
74
|
|
|
|
|
|
|
%$params, |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# ABSTRACT: Efficient autocomplete with term frequency and geolocation |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |