Catmandu::Store::Solr - A searchable store backed by Solr
use Catmandu::Store::Solr; my $store = Catmandu::Store::Solr->new(url => 'http://localhost:8983/solr' ); my $obj1 = $store->bag->add({ name => 'Patrick' }); printf "obj1 stored as %s\n" , $obj1->{_id}; # Force an id in the store my $obj2 = $store->bag->add({ _id => 'test123' , name => 'Nicolas' }); # send all changes to solr (committed automatically) $store->bag->commit; #transaction: rollback issued after 'die' $store->transaction(sub{ $bag->delete_all(); die("oops, didn't want to do that!"); }); my $obj3 = $store->bag->get('test123'); $store->bag->delete('test123'); $store->bag->delete_all; # All bags are iterators $store->bag->each(sub { ... }); $store->bag->take(10)->each(sub { ... }); # Some stores can be searched my $hits = $store->bag->search(query => 'name:Patrick');
Solr schemas need to support an identifier field (_id by default) and a bag field (_bag by default) to be able to store Catmandu items.
_id
_bag
Solr URL (http://localhost:8983/solr by default)
http://localhost:8983/solr
Field that _id is mapped to in Solr
Field that _bag is mapped to in Solr
When you issue $bag->commit, all changes made in the buffer are sent to solr, along with a commit. So committing in Catmandu merely means flushing changes;-).
When you wrap your subroutine within 'transaction', this behaviour is disabled temporarily. When you call 'die' within the subroutine, a rollback is sent to solr.
Remember that transactions happen at store level: after the transaction, all buffers of all bags are flushed to solr, and a commit is issued in solr.
#record 'test' added $bag->add({ _id => "test" }); #buffer flushed, and 'commit' sent to solr $bag->commit();
$bag->store->transaction(sub{ $bag->add({ _id => "test",title => "test" }); #call to die: rollback sent to solr die("oops, didn't want to do that!"); });
#record is still { _id => "test" }
Catmandu::Store, WebService::Solr
Nicolas Steenlant, nicolas.steenlant at ugent.be
nicolas.steenlant at ugent.be
Patrick Hochstenbach, patrick.hochstenbach at ugent.be
patrick.hochstenbach at ugent.be
Nicolas Franck, nicolas.franck at ugent.be
nicolas.franck at ugent.be
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Catmandu::Solr, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catmandu::Solr
CPAN shell
perl -MCPAN -e shell install Catmandu::Solr
For more information on module installation, please visit the detailed CPAN module installation guide.