Solr DIH中Tika处理器无法获取DB处理器传递的文件名问题
Solr DIH TikaEntityProcessor文件名空报错解决方案
报错的核心原因是TikaEntityProcessor未正确读取到父实体传递的文件路径,或路径格式不符合Tika的解析规则,可按以下步骤修改:
解决步骤
- 第一步:给Tika的url参数补充file协议前缀
TikaEntityProcessor的url参数默认按URL规则解析,本地文件路径需要添加file:///前缀(Windows系统3个斜杠为标准写法),修正后的url配置为url="file:///${attachment.path}" - 第二步:排查数据库path字段值
确认suppliers_tmp_files_view表中所有path字段值均为非空的绝对路径,避免使用相对路径;Windows路径建议统一用正斜杠/代替反斜杠\,避免转义异常。 - 第三步:测试路径有效性(可选)
可先在attachment实体的query中写死测试路径,验证Tika可正常读取文件后再恢复动态参数,比如将query改为select 'C:/test/demo.pdf' as path, id,supplier_tmp_id from suppliers_tmp_files_view where supplier_tmp_id='${supplier.id}'做调试。
修正后的完整配置
<dataConfig> <dataSource name="ds-db" driver="org.mariadb.jdbc.Driver" url="jdbc:mysql://localhost:3306/eepyakm?user=root" user="root" password="wpadmin"/> <dataSource name="ds-file" type="BinFileDataSource"/> <document> <entity name="supplier" query="select * from suppliers_tmp_view" dataSource="ds-db" deltaQuery="select id from suppliers_tmp_view where last_modified > '${dataimporter.last_index_time}'" deltaImportQuery="select * from suppliers_tmp_view where id='${dataimporter.delta.id}'"> <entity name="attachment" dataSource="ds-db" query="select * from suppliers_tmp_files_view where supplier_tmp_id='${supplier.id}'" deltaQuery="select id,supplier_tmp_id from suppliers_tmp_files_view where last_modified > '${dataimporter.last_index_time}'" parentDeltaQuery="select id from suppliers_tmp_view where id='${attachment.supplier_tmp_id}'"> <field name="path" column="path"/> <entity name="file" processor="TikaEntityProcessor" url="file:///${attachment.path}" format="text" dataSource="ds-file"> <field column="text"/> </entity> </entity> </entity> </document> </dataConfig>
内容的提问来源于stack exchange,提问作者jim
相关产品推荐
相关产品推荐

