Apache-Solr
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Apache/Solr/Document.pm
lib/Apache/Solr/Document.pod
lib/Apache/Solr/JSON.pm
lib/Apache/Solr/JSON.pod
lib/Apache/Solr/Result.pm
lib/Apache/Solr/Result.pod
lib/Apache/Solr/Tables.pm
lib/Apache/Solr/XML.pm
lib/Apache/Solr/XML.pod
t/01use.t
t/10endpoint.t
t/11expand.t
t/12facet.t
t/20xml.t
t/21json.t
t/30result.t
t/32version.t
t/a.pdf
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
lib/Apache/Solr.pm view on Meta::CPAN
}
sub _extract($) { panic "not implemented" }
#-------------------------
sub _core_admin($@)
{ my ($self, $action, $params) = @_;
$params->{core} ||= $self->core;
my $endpoint = $self->endpoint('cores', core => 'admin', params => $params);
my @params = %$params;
my $result = Apache::Solr::Result->new(params => [ %$params ], endpoint => $endpoint, core => $self);
$self->request($endpoint, $result);
$result;
}
sub coreStatus(%)
{ my ($self, %args) = @_;
$self->_core_admin('STATUS', \%args);
}
lib/Apache/Solr/JSON.pm view on Meta::CPAN
sub _select($$)
{ my ($self, $args, $params) = @_;
# select may be called more than once, but do not add wt each time
# again.
my @params = @$params;
my %params = @params;
unshift @params, wt => 'json';
my $endpoint = $self->endpoint('select', params => \@params);
my $result = Apache::Solr::Result->new(%$args,
params => \@params, endpoint => $endpoint, core => $self);
$self->request($endpoint, $result);
if(my $dec = $result->decoded)
{ # JSON uses different names!
my $r = $dec->{result} = delete $dec->{response};
$r->{doc} = delete $r->{docs};
}
$result;
}
sub _extract($$$)
{ my ($self, $params, $data, $ct) = @_;
my @params = (wt => 'json', @$params);
my $endpoint = $self->endpoint('update/extract', params => \@params);
my $result = Apache::Solr::Result->new(params => \@params
, endpoint => $endpoint, core => $self);
$self->request($endpoint, $result, $data, $ct);
$result;
}
sub _add($$$)
{ my ($self, $docs, $attrs, $params) = @_;
$attrs ||= {};
$params ||= {};
my $sv = $self->serverVersion;
$sv ge '3.1' or error __x"Solr version too old for updates in JSON syntax";
my @params = (wt => 'json', %$params);
my $endpoint = $self->endpoint
( ($sv lt '4.0' ? 'update/json' : 'update')
, params => \@params
);
my $result = Apache::Solr::Result->new(params => \@params
, endpoint => $endpoint, core => $self);
# We cannot create HASHes with twice the same key in Perl, so cannot
# produce the syntax for adding multiple documents. Try to save it.
delete $attrs->{boost}
if $attrs->{boost} && $attrs->{boost}==1.0;
exists $attrs->{$_} && ($params->{$_} = delete $attrs->{$_})
for qw/commit commitWithin overwrite boost/;
my $add;
if(@$docs==1)
{ $add = {add => {%$attrs, doc => $self->_doc2json($docs->[0])}} }
elsif(keys %$attrs)
{ # in combination with attributes only
error __x"Unable to add more than one doc with JSON interface";
}
else
{ $add = [ map $self->_doc2json($_), @$docs ] }
$self->request($endpoint, $result, $add);
$result;
}
sub _doc2json($)
{ my ($self, $this) = @_;
my %doc;
foreach my $fieldname ($this->fieldNames)
{ my @f;
foreach my $field ($this->fields($fieldname))
{ my $update = $field->{update} || 'value';
lib/Apache/Solr/Result.pm view on Meta::CPAN
use Scalar::Util qw(weaken);
use Apache::Solr::Document ();
use Data::Dumper;
$Data::Dumper::Indent = 1;
$Data::Dumper::Quotekeys = 0;
use overload
'""' => 'endpoint'
, bool => 'success';
#----------------------
sub new(@) { my $c = shift; (bless {}, $c)->init({@_}) }
sub init($)
{ my ($self, $args) = @_;
my $p = $self->{ASR_params} = $args->{params} or panic;
$self->{ASR_endpoint} = $args->{endpoint} or panic;
my %params = @$p;
$self->{ASR_start} = time;
$self->request($args->{request});
$self->response($args->{response});
$self->{ASR_pages} = [ $self ]; # first has non-weak page-table
weaken $self->{ASR_pages}[0]; # no reference loop!
lib/Apache/Solr/Result.pod view on Meta::CPAN
=head1 METHODS
=head2 Constructors
=over 4
=item Apache::Solr::Result-E<gt>B<new>(%options)
-Option --Default
core undef
endpoint <required>
params <required>
request undef
response undef
sequential false
=over 2
=item core => L<Apache::Solr|Apache::Solr> object
=item endpoint => URI
=item params => ARRAY
=item request => HTTP::Request object
=item response => HTTP::Response object
=item sequential => BOOLEAN
[1.06] By setting this, you indicate that you will process the documents
t/10endpoint.t view on Meta::CPAN
#!/usr/bin/perl
# Test endpoint construction
use warnings;
use strict;
use lib 'lib';
use Apache::Solr;
use Test::More tests => 4;
# the server will not be called in this script.
my $server = 'http://localhost:8080/solr';
my $core = 'my-core';
my $solr = Apache::Solr->new(server => $server, core => $core);
ok(defined $solr, 'instantiated client');
isa_ok($solr, 'Apache::Solr');
my $uri1 = $solr->endpoint('update', params => [tic => 1, tac => '&']);
isa_ok($uri1, 'URI');
is($uri1->as_string, "$server/$core/update?tic=1&tac=%26");
ok(defined $solr, "instantiated client in $format");
isa_ok($solr, 'Apache::Solr::'.$FORMAT);
my $result = eval { $solr->commit };
ok(!$@, 'try commit:'.$@);
cmp_ok($result->solrStatus, '==', 0, 'Commit status success');
isa_ok($result, 'Apache::Solr::Result');
is($result->endpoint, "$result");
#$result->showTimings(\*STDERR);
ok($result->success, 'successful');
# reset the database
my $r0 = $solr->delete(id => [ qw/A B C/ ]);
ok($r0->success, 'delete succeeded');
#warn Dumper $r0;
### test $solr->addDocument()
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.705 second using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )