Consider this successful Solr commit:
$ curl
http://someAddress:8983/solr/update?commit=true -H
"Content-Type: text/xml" --data-binary '<add><doc><field
name="id">abcd</field><field name="text">This is a
test.</field></doc></add>'
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int
name="QTime">166</int></lst>
</response>
However, this code in PHP fails:
#!/usr/bin/php -q
$ cat solrTest.php
<?
require_once('/home/dotancohen/SolrPhpClient/Apache/Solr/Service.php');
$solr = new Apache_Solr_Service('someAddress', 8983, '/solr');
$doc = new Apache_Solr_Document();
$doc->id = "efgh";
$doc->text = "This is a test from PHP.";
$documents[] = $doc;
try {
$solr->addDocuments( $documents );
$solr->commit();
$solr->optimize();
} catch(Exception $e) {
echo $e->getMessage();
}
?>
$ ./solrTest.php
'400' Status: Bad Request
I stress that the 'id' field is of type 'string'. Why might the curl
command work, but PHP not? I have used this Solr-Php-Client library to
access other Solr clients before, so I know that it does work and is
configured properly.
Thanks.
--
Dotan Cohen
http://gibberish.co.il
http://what-is-what.com