【发布时间】:2016-07-09 08:28:23
【问题描述】:
前几天我刚开始使用 Solr 6.0,并制作了一个脚本,用于通过使用 curl 的 php 脚本更新 Solr 索引。 但是现在,使用下面的 php 脚本更新时会出现重复的条目。
现在的架构是这样的:id(唯一键字段)、url、关键字、描述、标题。
这是因为我没有使用架构在 url 上指定明确的唯一键字段吗?
我希望将 url 作为唯一键,这样它将防止 Solr 在更新时索引重复项,并在重复时覆盖。你是怎么做到的?
<?php
// apt-get install php5 libapache2-mod-php5 php5-curl
// curl 'http://localhost:8983/solr/update/csv?fieldnames=url,keywords,description,title&commit=true' -H 'Content-type:text/plain; charset=utf-8' --data-binary @$file
$SOLR_SERVER = '127.0.0.1';
$CORE = 'core1';
ob_start();
$callback = &$_REQUEST['fd-callback'];
$url = 'http://'. $SOLR_SERVER .':8983/solr/'. $CORE .'/update/csv?fieldnames=url,keywords,description,title&commit=true';
if (!empty($_FILES['fd-file']) and is_uploaded_file($_FILES['fd-file']['tmp_name'])) {
$name = $_FILES['fd-file']['name'];
$data = file_get_contents($_FILES['fd-file']['tmp_name']);
} else {
$name = urldecode(@$_SERVER['HTTP_X_FILE_NAME']);
$data = file_get_contents("php://input");
}
$header = array("Content-type:text/csv; charset=utf-8");
$post = $data;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
//curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_exec($ch);
curl_close($ch);
if ($ch) {
$output = 'Upload Success!';
}else {
$output = 'Upload did not work!';
}
// $opt = &$_REQUEST['upload_option'];
// isset($opt) and $output .= "\nReceived upload_option with value $opt";
if ($callback) {
header('Content-Type: text/html; charset=utf-8');
$output = addcslashes($output, "\\\"\0..\x1F");
echo '<!DOCTYPE html><html><head></head><body><script type="text/javascript">',
"try{window.top.$callback(\"$output\")}catch(e){}</script></body></html>";
} else {
header('Content-Type: text/plain; charset=utf-8');
echo $output;
}
?>
【问题讨论】:
标签: php database solr full-text-search