我正在使用 Solrphp 扩展用于与 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
code:
$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
EDIT #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
)。我不想要这样。