多表利用DIH批量导入数据并建立索引注意事项
如果希望同时对多个表进行全文检索,那我们该如何处理呢?利用DIH导入数据并建立索引时。schema.xml中配置了uniqueKey为id
<uniqueKey>id</uniqueKey>
如果多表主键都为id的话索引会被覆盖
<!--deltaImportQuery和deltaQuery为增量导入时使用。--> <entity name="case" pk="id" query="SELECT id,title, summary, 'case' as type FROM case" deltaImportQuery="SELECT id, title, summary, 'case' as type from case WHERE id='${dih.delta.id}'" deltaQuery="SELECT id, title, summary, 'case' as type FROM case WHERE create_time > '${dih.last_index_time}'" > <!--field用于配置schema.xml中field和数据库字段的对应关系。column:数据库中字段名称,name:schema.xml中配置的名称--> <field column="id" name="id"/> <field column="title" name="title"/> <field column="summary" name="summary"/> </entity> <!--deltaImportQuery和deltaQuery为增量导入时使用。--> <entity name="casetest" pk="id" query="SELECT id,title, summary, 'case_test' as type FROM casetest" deltaImportQuery="SELECT id, title, summary, 'case_test' as type from casetest WHERE id='${dih.delta.id}'" deltaQuery="SELECT id, title, summary, 'case_test' as type FROM casetest WHERE create_time > '${dih.last_index_time}'" > <!--field用于配置schema.xml中field和数据库字段的对应关系。column:数据库中字段名称,name:schema.xml中配置的名称--> <field column="id" name="id"/> <field column="title" name="title"/> <field column="summary" name="summary"/> <field column="type" name="type"/> </entity>
由于id是唯一键,如果id重复索引会被覆盖掉。此时可以加个简易的标识,以便构造不同表的uniqueKey
修改后配置文件
<!--deltaImportQuery和deltaQuery为增量导入时使用。--> <entity name="case" pk="id" query="SELECT concat('case_Type_', id) as id,title, summary, 'case' as type FROM case" deltaImportQuery="SELECT concat('case_Type_', id) as id, title, summary, 'case' as type from case WHERE id='${dih.delta.id}'" deltaQuery="SELECT concat('case_Type_', id) as id, title, summary, 'case' as type FROM case WHERE create_time > '${dih.last_index_time}'" > <!--field用于配置schema.xml中field和数据库字段的对应关系。column:数据库中字段名称,name:schema.xml中配置的名称--> <field column="id" name="id"/> <field column="title" name="title"/> <field column="summary" name="summary"/> </entity> <!--deltaImportQuery和deltaQuery为增量导入时使用。--> <entity name="casetest" pk="id" query="SELECT concat('case_test_Type_', id) as id,title, summary, 'case_test' as type FROM casetest" deltaImportQuery="SELECT concat('case_test_Type_', id) as id, title, summary, 'case_test' as type from casetest WHERE id='${dih.delta.id}'" deltaQuery="SELECT concat('case_test_Type_', id) as id, title, summary, 'case_test' as type FROM casetest WHERE create_time > '${dih.last_index_time}'" > <!--field用于配置schema.xml中field和数据库字段的对应关系。column:数据库中字段名称,name:schema.xml中配置的名称--> <field column="id" name="id"/> <field column="title" name="title"/> <field column="summary" name="summary"/> <field column="type" name="type"/> </entity>
扫描公众号,关注更多信息
---------------------------------------------------------------------------------我是分割线--------------------------------------------------------------------------to be a better me, talk is cheap show me the code
版权所有,转载请注明原文链接。
文中有不妥或者错误的地方还望指出,以免误人子弟。如果觉得本文对你有所帮助不妨【推荐】一下!如果你有更好的建议,可以给我留言讨论,共同进步!
再次感谢您耐心的读完本篇文章。
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
分类:
java
标签:
solr_lucence
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?