Skip to content

Instantly share code, notes, and snippets.

@MagnusEnger
Created April 10, 2014 13:47
Show Gist options
  • Save MagnusEnger/10384065 to your computer and use it in GitHub Desktop.
Save MagnusEnger/10384065 to your computer and use it in GitHub Desktop.
Catmandu Atom ingest v2
#!/usr/bin/perl
use Catmandu::Importer::Atom;
use Catmandu::Store::ElasticSearch;
use Data::Dumper;
use Modern::Perl;
my $feed = 'http://planet.code4lib.org/atom.xml';
# Set up importer and store
my $importer = Catmandu::Importer::Atom->new( url => $feed );
my $store = Catmandu::Store::ElasticSearch->new( index_name => 'dbabel' );
# Start from scratch during testing
$store->bag->delete_all;
# Loop through items and store them
my $n = $importer->each(sub {
my $hashref = $_[0];
# Set a custom ID
$hashref->{'_id'} = $hashref->{'id'};
$store->bag->add( $hashref );
});
$store->bag->commit;
# Do a search
my $hits = $store->bag->search( query => 'library' )->to_array;
foreach my $hit ( @{ $hits } ) {
say "* <", $hit->{'_id'}, "> ", $hit->{'title'};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment