我正在使用日光浴室来实现 solr 搜索。我需要将我的文件索引到 solr。我正在使用以下代码来执行此操作。
require('init.php');
use Solarium\Plugin\BufferedAdd\Event\Events;
use Solarium\Plugin\BufferedAdd\Event\PreFlush as PreFlushEvent;
use Solarium\Plugin\BufferedAdd\Event\PostCommit as PostCommitEvent;
/////////////////This function adds the knowledge maps to solr//////////////////////////////
$results_index = query(" select indexed_id from update_solr WHERE table_name='knowledgemaps'");
$results = query(" select m_id,k_id, m_title, m_des from knowledgemaps WHERE k_id>{$results_index[0]['indexed_id']}");
$client = new Solarium\Client($config);
$buffer = $client->getPlugin('bufferedadd');
$buffer->setBufferSize(10);
for($i=0;$i<count($results);$i++) {
// also register an event hook to display what is happening
$client->getEventDispatcher()->addListener(
Events::PRE_FLUSH,
function (PreFlushEvent $event) {
echo 'Flushing buffer (' . count($event->getBuffer()) . 'docs)<br/>';
}
);
// Create a document
$doc = array();
$doc["map_id"]=$results[$i]["m_id"];
$doc["user_id"]=$results[$i]["k_id"];
$doc["map_title"]=$results[$i]["m_title"];
if(isset($results[$i]["m_des"])&&is_null($results[$i]["m_des"])){
$doc["map_des"]=$results[$i]["m_des"];
}
$buffer->createDocument($doc);
}
$buffer->flush();
当我执行代码时,我没有收到任何错误。它给出了正确的刷新文档数。但是在 solr 中没有数据被索引。
是否需要一些额外的代码来索引信息