| 1 | # Copyright Infomation | ||
| 2 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 3 | # Author : Dr. Ahmed Amin Elsheshtawy, Ph.D. | ||
| 4 | # Website: https://github.com/mewsoft/Nile, http://www.mewsoft.com | ||
| 5 | # Email : mewsoft@cpan.org, support@mewsoft.com | ||
| 6 | # Copyrights (c) 2014-2015 Mewsoft Corp. All rights reserved. | ||
| 7 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 8 | package Nile::Plugin::Elasticsearch; | ||
| 9 | |||
| 10 | our $VERSION = '0.55'; | ||
| 11 | our $AUTHORITY = 'cpan:MEWSOFT'; | ||
| 12 | |||
| 13 | =pod | ||
| 14 | |||
| 15 | =encoding utf8 | ||
| 16 | |||
| 17 | =head1 NAME | ||
| 18 | |||
| 19 | Nile::Plugin::Elasticsearch - Elasticsearch client plugin for the Nile framework. | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | my $client = $app->plugin->elasticsearch; | ||
| 24 | |||
| 25 | $app->dump($client->nodes->info); | ||
| 26 | |||
| 27 | $app->dump($client->nodes->stats); | ||
| 28 | |||
| 29 | $client->index( | ||
| 30 | index => 'my_index', | ||
| 31 | type => 'blog_post', | ||
| 32 | id => 123, | ||
| 33 | body => { | ||
| 34 | title => "Elasticsearch clients", | ||
| 35 | content => "Interesting content...", | ||
| 36 | date => "2013-09-23" | ||
| 37 | } | ||
| 38 | ); | ||
| 39 | |||
| 40 | my $doc = $client->get( | ||
| 41 | index => 'my_index', | ||
| 42 | type => 'blog_post', | ||
| 43 | id => 123, | ||
| 44 | ignore => [404,409], | ||
| 45 | ); | ||
| 46 | |||
| 47 | $app->dump($doc); | ||
| 48 | |||
| 49 | my $results = $client->search( | ||
| 50 | index => 'my_index', | ||
| 51 | body => { | ||
| 52 | query => { | ||
| 53 | match => { | ||
| 54 | title => "elasticsearch" | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | ); | ||
| 59 | |||
| 60 | $app->dump($results); | ||
| 61 | |||
| 62 | =head1 DESCRIPTION | ||
| 63 | |||
| 64 | Nile::Plugin::Elasticsearch - Elasticsearch client plugin for the Nile framework. | ||
| 65 | |||
| 66 | Returns L<Search::Elasticsearch> object. All methods of L<Search::Elasticsearch> are supported. | ||
| 67 | |||
| 68 | Plugin settings in th config file under C<plugin> section. | ||
| 69 | |||
| 70 | <plugin> | ||
| 71 | |||
| 72 | <elasticsearch> | ||
| 73 | <nodes>localhost:9200</nodes> | ||
| 74 | </elasticsearch> | ||
| 75 | |||
| 76 | </plugin> | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | use Nile::Plugin; | ||
| 81 | use Search::Elasticsearch; | ||
| 82 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 83 | sub main { | ||
| 84 | my ($self, $arg) = @_; | ||
| 85 | my $app = $self->app; | ||
| 86 | my $setting = $self->setting(); | ||
| 87 | if (defined($setting->{nodes}) && (ref($setting->{nodes}) ne "ARRAY")) { | ||
| 88 | $setting->{nodes} = [$setting->{nodes}]; | ||
| 89 | } | ||
| 90 | rebless => Search::Elasticsearch->new(%{$setting}); | ||
| 91 | } | ||
| 92 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 93 | |||
| 94 | =pod | ||
| 95 | |||
| 96 | =head1 Bugs | ||
| 97 | |||
| 98 | This project is available on github at L<https://github.com/mewsoft/Nile>. | ||
| 99 | |||
| 100 | =head1 HOMEPAGE | ||
| 101 | |||
| 102 | Please visit the project's homepage at L<https://metacpan.org/release/Nile>. | ||
| 103 | |||
| 104 | =head1 SOURCE | ||
| 105 | |||
| 106 | Source repository is at L<https://github.com/mewsoft/Nile>. | ||
| 107 | |||
| 108 | =head1 SEE ALSO | ||
| 109 | |||
| 110 | See L<Nile> for details about the complete framework. | ||
| 111 | |||
| 112 | =head1 AUTHOR | ||
| 113 | |||
| 114 | Ahmed Amin Elsheshtawy, احمد امين الششتاوى <mewsoft@cpan.org> | ||
| 115 | Website: http://www.mewsoft.com | ||
| 116 | |||
| 117 | =head1 COPYRIGHT AND LICENSE | ||
| 118 | |||
| 119 | Copyright (C) 2014-2015 by Dr. Ahmed Amin Elsheshtawy احمد امين الششتاوى mewsoft@cpan.org, support@mewsoft.com, | ||
| 120 | L<https://github.com/mewsoft/Nile>, L<http://www.mewsoft.com> | ||
| 121 | |||
| 122 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||
| 123 | |||
| 124 | =cut | ||
| 125 | |||
| 126 | 1; |