| 1 | package Search::Elasticsearch::Plugin::Langdetect; | ||
| 2 | use Moo; | ||
| 3 | with 'Search::Elasticsearch::Plugin::Langdetect::API'; | ||
| 4 | with 'Search::Elasticsearch::Role::Client::Direct'; | ||
| 5 | __PACKAGE__->_install_api('langdetect'); | ||
| 6 | |||
| 7 | use Search::Elasticsearch 2.00 (); | ||
| 8 | |||
| 9 | use vars '$VERSION'; | ||
| 10 | $VERSION = '0.06'; | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | use Search::Elasticsearch; | ||
| 15 | use Search::Elasticsearch::Plugin::Langdetect; | ||
| 16 | |||
| 17 | use Search::Elasticsearch(); | ||
| 18 | my $es = Search::Elasticsearch->new( | ||
| 19 | nodes => \@nodes, | ||
| 20 | plugins => ['Langdetect'] | ||
| 21 | ); | ||
| 22 | |||
| 23 | my $e = Search::Elasticsearch->new(...); | ||
| 24 | my $ld = $e->langdetect; | ||
| 25 | |||
| 26 | my $lang = $ld->detect_language( "Hello World" ); | ||
| 27 | # en | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub _init_plugin { | ||
| 32 | my ( $class, $params ) = @_; | ||
| 33 | |||
| 34 | Moo::Role->apply_roles_to_object( $params->{client}, | ||
| 35 | qw(Search::Elasticsearch::Plugin::Langdetect::Namespace) ); | ||
| 36 | } | ||
| 37 | |||
| 38 | package Search::Elasticsearch::Plugin::Langdetect::Namespace; | ||
| 39 | use Moo::Role; | ||
| 40 | |||
| 41 | has 'langdetect' => ( is => 'lazy', init_arg => undef ); | ||
| 42 | |||
| 43 | sub _build_langdetect { | ||
| 44 | shift->_build_namespace('+Search::Elasticsearch::Plugin::Langdetect'); | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; | ||
| 48 | |||
| 49 | __END__ |