好的,我就是这样做的
我正在使用 solr DHI
在 solrconfig.xml 中
<requestHandler name="/dataimport_fromXML" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data.import.xml</str>
<str name="update.chain">dedupe</str>
</lst>
</requestHandler>
和 data.import.xml 文件
<dataConfig>
<dataSource type="BinFileDataSource" name="data"/>
<dataSource type="FileDataSource" name="main"/>
<document>
<!-- url : the url for the xml file that holde the metadata -->
<entity name="rec" processor="XPathEntityProcessor" url="${solr.install.dir:}solr/solr_core_name/filestore/docs_metaData/metaData.xml" forEach="/docs/doc" dataSource="main" transformer="RegexTransformer,DateFormatTransformer">
<field column="resourcename" xpath="//resourcename" name="resourceName" />
<field column="title" xpath="//title" name="title" />
<field column="subject" xpath="//subject" name="subject"/>
<field column="description" xpath="//description" name="description"/>
<field column="comments" xpath="//comments" name="comments"/>
<field column="author" xpath="//author" name="author"/>
<field column="keywords" xpath="//keywords" name="keywords"/>
<!-- baseDir: path to the folder that containt the files (pdf | doc | docx | ...) -->
<entity name="files" dataSource="null" rootEntity="false" processor="FileListEntityProcessor" baseDir="${solr.install.dir:}solr/solr_core_name/filestore/docs_folder" fileName="${rec.resourcename}" onError="skip" recursive="false">
<field column="fileAbsolutePath" name="filePath" />
<field column="resourceName" name="resourceName" />
<field column="fileSize" name="size" />
<field column="fileLastModified" name="lastModified" />
<!-- for etch file extracte metadata if not in the xml metadata file -->
<entity name="file" processor="TikaEntityProcessor" dataSource="data" format="text" url="${files.fileAbsolutePath}" onError="skip" recursive="false">
<field column="title" name="title" meta="true"/>
<field column="subject" name="subject" meta="true"/>
<field column="description" name="description" meta="true"/>
<field column="comments" name="comments" meta="true"/>
<field column="Author" name="author" meta="true"/>
<field column="Keywords" name="keywords" meta="true"/>
</entity>
</entity>
</entity>
</document>
</dataConfig>
之后你要做的就是创建xml文件(metaData.xml)
<docs>
<doc>
<resourcename>fileName.pdf</resourcename>
<title></title>
<subject></subject>
<description></description>
<comments></comments>
<author></author>
<keywords></keywords>
</doc>
</docs>
将所有文件放在一个文件夹中
"${solr.install.dir:}solr/solr_core_name/filestore/docs_folder"
${solr.install.dir:} 是 solr 主文件夹
关于问题的更新
如何将literal.id 设置为filePath
在 data.import.xml 中将 fileAbsolutePath 映射到 id
<field column="fileAbsolutePath" name="id" />
最后一件事
在这个例子中,id是我使用的自动生成的
<updateRequestProcessorChain name="dedupe">
witch 根据内容的哈希创建一个唯一的 id 以避免重复