Solr添加和更新pdf文件

Solr add and update pdf files

我想添加和更新 pdf 文件到 solrs 索引。 我的场景:我有一个目录 (mainDir),应该对其进行索引。该目录包含许多带有 pdf 文件的子目录。可以创建、更新或删除新的 pdf 文件和子目录。

我已经创建了一个数据导入处理程序,它对我目录中的所有文件进行递归索引。这是我的配置:

<dataConfig>
  <dataSource type="BinFileDataSource"/>
  <document>  
    <entity name="file" 
            processor="FileListEntityProcessor" 
            dataSource="null" 
            fileName=".*pdf" 
            rootEntity="false" 
            baseDir="/mainDir" 
            recursive="true" >

            <field column="file" name="fileName"/>
            <field column="fileAbsolutePath" name="fileAbsolutePath"/>
            <field column="fileDir" name="fileDir"/>            

        <entity name="pdf" processor="TikaEntityProcessor" url="${file.fileAbsolutePath}" format="text">

            <field column="title" name="title"/>
            <field column="text" name="_text_"/>

        </entity>     
    </entity>   
  </document>
</dataConfig>

我 运行 DIH,它有效,但我不知道如何添加/更新单个 pdf 文件。 提交对索引的更改的最佳方法是什么。稍后 node.js API 应该注意到 solr 的变化。

索引一份文件

只需调用 http://localhost:8983/solr/my_collection/dataimport?command=full-import

或使用 curl

curl http://localhost:8983/solr/my_collection/update -H "Content-Type: text/xml" -T "myfile.pdf" -X POST

参考:https://lucene.apache.org/solr/guide/8_5/uploading-data-with-index-handlers.html#using-curl-to-perform-updates

防止重复

https://lucene.apache.org/solr/guide/8_5/de-duplication.html#de-duplication

你可以使用这样的东西,你映射的 id 是根据文档的内容自动生成的 防止索引上的重复文件

<updateRequestProcessorChain name="dedupe">
        <processor class="solr.processor.SignatureUpdateProcessorFactory">
            <bool name="enabled">true</bool>
            <str name="signatureField">id</str>
            <bool name="overwriteDupes">true</bool>
            <str name="fields">text</str>
            <str name="signatureClass">solr.processor.Lookup3Signature</str>
        </processor>
        <processor class="solr.LogUpdateProcessorFactory" />
        <processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>

并在 name="/update/extract" 和 name="/dataimport" name="/update" 的请求处理程序中添加此

<str name="update.chain">dedupe</str>

这也有帮助

<initParams path="/update/**">
        <lst name="defaults">
            <str name="update.chain">dedupe</str>
        </lst>
</initParams>

last_index_time

你可以把 <field name="updated" type="date" default="NOW"/> 放在你的 schema.xml

如果您想在数据配置中使用该值,请使用此变量:'${dataimporter.last_index_time}' 最后索引时间存储在 data.import.properties

对于 node.js 与 solr

参考:https://www.npmjs.com/package/solr-node