我正在尝试使用solr PHP Client . 当我尝试添加文档时,它返回400状态 . 我不知道我做错了什么,我不熟悉索尔 . 下面是我的代码和schema.xml文件 .
我使用的是solr 4.10.3和tomcat 7
提前致谢
$solr = new Apache_Solr_Service('localhost', '8080', '/solr/#/core0');
if (!$solr->ping()) {
echo 'Solr service not responding.';
exit;
} else {
$fileContent = $_GET['fileContent'];
$title = trim($_GET['title']);
$desription = $_GET['description'];
$fileId = trim($_GET['fileId']);
$docs = array(
'doc1' => array(
'id' => 1,
'fileid' => 'file1',
'title' => 'title1'
));
$documents = array();
$part = new Apache_Solr_Document();
foreach ($docs as $item => $fields) {
foreach ($fields as $key => $value) {
if (is_array($value)) {
foreach ($value as $data) {
$part->setMultiValue($key, $data);
}
}
else {
$part->$key = $value;
}
}
$documents[] = $part;
}
// Load the documents into the index
try {
$a = $solr->addDocuments($documents);
$solr->commit();
$solr->optimize();
} catch (Exception $e) {
echo $e->getMessage();
}
die;
$offset = 0;
$limit = 10;
$queries = array('id:'.$fileId);
foreach ($queries as $query) {
$response = $solr->search($query, $offset, $limit);
if ($response->getHttpStatus() == 200) {
// print_r( $response->getRawResponse() );
if ($response->response->numFound > 0) {
echo "$query
";
foreach ($response->response->docs as $doc) {
echo "$doc->id $doc->title
";
}
echo '
';
}
} else {
echo $response->getHttpStatusMessage();
}
}
}
}
schema.xml中
id