Apache-Solr

 view release on metacpan or  search on metacpan

lib/Apache/Solr/Document.pod  view on Meta::CPAN

=encoding utf8

=head1 NAME

Apache::Solr::Document - Apache Solr (Lucene) Document container

=head1 SYNOPSIS

  # create and upload a new document
  my $doc = Apache::Solr::Document->new(...);
  $doc->addField(id => 'tic');
  $doc->addFields( {name => 'tac', foot => 'toe'}, boost => 2);

  $solr->addDocument($doc, commit => 1, overwrite => 1)

  # take results
  my $results = $solr->select(
    q  => 'text:gold',              # search text-fields for 'gold'
    hl => { field => 'content' }    # highlight 'gold' in content'

lib/Apache/Solr/JSON.pm  view on Meta::CPAN

sub request($$;$$)
{	my ($self, $url, $result, $body, $body_ct) = @_;

	if(ref $body && ref $body ne 'SCALAR')
	{	$body_ct ||= 'application/json; charset=utf-8';
		$body      = \$self->json->encode($body);
	}

	# Solr server 3.6.2 seems not to detect the JSON input from the
	# body content, so requires this work-around
	# https://solr.apache.org/guide/6_6/uploading-data-with-index-handlers.html#UploadingDatawithIndexHandlers-JSONUpdateConveniencePaths
	$url =~ s!/update\?!/update/json?!;

	$self->SUPER::request($url, $result, $body, $body_ct);
}


sub decodeResponse($)
{	my ($self, $resp) = @_;

	# At least until Solr 4.0 response ct=text/plain while producing JSON

t/20xml.t  view on Meta::CPAN

isa_ok($d3b, 'Apache::Solr::Document', 'got 2 answer');
$id3{$d3b->uniqueId} = $d3b;
cmp_ok(keys %id3, '==', 2, 'both documents found');
ok($id3{A}, 'found id=A');
ok($id3{B}, 'found id=B');

my $h3a = $t3->highlighted($id3{A});
isa_ok($h3a, 'Apache::Solr::Document', 'got 1 hl answer');
is($h3a->_content, '<html>tic <em>tac</em>', 'test hl content');

### upload document

#my $t4 = $solr->extractDocument( #overwrite => 1, commit => 1
#   extractOnly => 1, file => 't/a.pdf');
my $t4 = $solr->extractDocument(overwrite => 1, commit => 1,
   literal_id => 'C', file => 't/a.pdf');
ok($t4, 'uploaded document 3, an pdf');

done_testing;

t/21json.t  view on Meta::CPAN

isa_ok($d3b, 'Apache::Solr::Document', 'got 2 answer');
$id3{$d3b->uniqueId} = $d3b;
cmp_ok(keys %id3, '==', 2, 'both documents found');
ok($id3{A}, 'found id=A');
ok($id3{B}, 'found id=B');

my $h3a = $t3->highlighted($id3{A});
isa_ok($h3a, 'Apache::Solr::Document', 'got 1 hl answer');
is($h3a->_content, '<html>tic <em>tac</em>', 'test hl content');

### upload document

#my $t4 = $solr->extractDocument( #overwrite => 1, commit => 1
#   extractOnly => 1, file => 't/a.pdf');
my $t4 = $solr->extractDocument(overwrite => 1, commit => 1,
   literal_id => 'C', file => 't/a.pdf');
ok($t4, 'uploaded document 3, an pdf');

done_testing;



( run in 3.612 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )