Created
April 10, 2014 13:47
-
-
Save MagnusEnger/10384065 to your computer and use it in GitHub Desktop.
Catmandu Atom ingest v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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