我正在使用 Solr 的php 扩展来与 Apache Solr 交互。我正在索引数据库中的数据。我也想索引外部文件(如 PDF、PPTX)的内容。
索引的逻辑是:假设schema.xml
定义了以下字段:
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="created" type="tlong" indexed="true" stored="true" />
<field name="name" type="text_general" indexed="true" stored="true"/>
<field name="filepath" type="text_general" indexed="false" stored="true"/>
<field name="filecontent" type="text_general" indexed="false" stored="true"/>
单个数据库条目可能/可能没有存储文件。
因此,以下是我的索引代码:
$post = stdclass object having the database content
$doc = new SolrInputDocument();
$doc->addField('id', $post->id);
$doc->addField('name', $post->name);
....
....
$res = $client->addDocument($doc);
$client->commit();
接下来,我想将PDF文件的内容添加到与上面相同的solr文档中。
这是curl
代码:
$ch = curl_init('
http://localhost:8010/solr/update/extract?');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, array('myfile'=>'@'.$post->filepath));
$result= curl_exec ($ch);
但是,我想我错过了一些东西。我阅读了文档,但无法找到检索文件内容然后将其添加到现有 solr 文档中的方法field: filecontent
编辑#1:如果我尝试literal.id=xyz
在 curl 请求中设置,它会创建一个新的 solr 文档,其中包含id=xyz
. 我不想创建新的 solr 文档。我希望 pdf 的内容被索引并存储为先前创建的 solr 文档中的一个字段。
$doc = new SolrInputDocument();//Solr document is created
$doc->addField('id', 98765);//The solr document created above is assigned an id=`98765`
....
....
$ch = curl_init('
http://localhost:8010/solr/update/extract?literal.id=1&literal.name=Name&commit=true');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, array('myfile'=>'@'.$post->filepath));
$result= curl_exec ($ch);
我希望上面的 solr 文档(id = 98765
)有一个字段,其中 pdf 的内容被索引和存储。
但是 cURL 请求(如上)创建了另一个新文档(带有id = 1
)。我不想要那个。