Skip to content

Commit

Permalink
replace deprecated ElasticSearch with Search::ElasticSearch
Browse files Browse the repository at this point in the history
ElasticSearch is deprecated and no longer available on CPAN, so update
the code to use Search::ElasticSearch instead.
  • Loading branch information
haarg committed Jul 9, 2015
1 parent e057900 commit 1494d51
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion cpanfile
Expand Up @@ -26,7 +26,8 @@ requires 'DateTime::Format::HTTP';
requires 'DateTime::Format::ISO8601';
requires 'Digest::MD5';
requires 'Digest::SHA1';
requires 'ElasticSearch';
requires 'Search::Elasticsearch';
requires 'ElasticSearch::SearchBuilder';
requires 'Encode', '2.51';
requires 'Exporter';
requires 'Format::Human::Bytes';
Expand Down
28 changes: 15 additions & 13 deletions lib/MetaCPAN/Sitemap.pm
Expand Up @@ -8,7 +8,8 @@ use warnings;
use autodie;

use Carp;
use ElasticSearch;
use Search::Elasticsearch;
use ElasticSearch::SearchBuilder;
use File::Spec;
use MetaCPAN::Web::Types qw( HashRef Int Str );
use Moose;
Expand Down Expand Up @@ -51,19 +52,21 @@ sub process {
# actually exist and b) the directory itself is writeable.

# Get started. Create the ES object and the scrolled search object.
my $es = ElasticSearch->new(
servers => 'api.metacpan.org',
no_refresh => 1,
my $es = Search::Elasticsearch->new(
nodes => [ 'api.metacpan.org' ],
cxn_pool => 'Static::NoPing',
send_get_body_as => 'POST',
);
defined $es or croak "Unable to create ElasticSearch: $!";

my $field_name = $self->field_name;

# Start off with standard search parameters ..

my %search_parameters = (
index => 'v0',
size => 5000,
type => $self->object_type,
fields => [ $self->field_name ],
fields => [ $field_name ],
);

# ..and augment them if necesary.
Expand All @@ -73,11 +76,11 @@ sub process {
# Copy the filter over wholesale into the search parameters, and add
# the filter fields to the field list.

$search_parameters{'queryb'} = $self->filter;
$search_parameters{'body'} = ElasticSearch::SearchBuilder->new->query($self->filter);
push @{ $search_parameters{'fields'} }, keys %{ $self->filter };
}

my $scrolled_search = $es->scrolled_search(%search_parameters);
my $scrolled_search = $es->scroll_helper(%search_parameters);

# Open the output file, get ready to pump out the XML.

Expand All @@ -90,12 +93,11 @@ sub process {
= 'https://metacpan.org/' . $self->cpan_directory . q{/};
}

do {
my @hits = $scrolled_search->drain_buffer;
while ($scrolled_search->refill_buffer) {
push @urls,
map { $metacpan_url . $_->{'fields'}->{ $self->field_name } }
@hits;
} while ( $scrolled_search->next() );
map { $metacpan_url . $_->{'fields'}->{ $field_name } }
$scrolled_search->drain_buffer;
}

$_ = $_ . q{ } for @urls;

Expand Down

0 comments on commit 1494d51

Please sign in to comment.