侧边栏壁纸
  • 累计撰写 781 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

数据导入

Dettan
2021-04-10 / 0 评论 / 0 点赞 / 104 阅读 / 3,128 字
温馨提示:
本文最后更新于 2022-04-30,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
core文件夹里的solrconfig.xml
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
  <lst name="defaults">
    <str name="config">DIHconfig.xml</str>
  </lst>
</requestHandler>

同文件夹下创建一个DIHconfig.xml




官方示例

<dataConfig>
  <dataSource driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:./example-DIH/hsqldb/ex" 
    user="sa" password="secret"/> 
  <document> 
    <entity name="item" query="select * from item"
            deltaQuery="select id from item where last_modified > '${dataimporter.last_index_time}'"> 
      <field column="NAME" name="name" />
  &lt;entity name=&quot;feature&quot;
          query=&quot;select DESCRIPTION from FEATURE where ITEM_ID='${item.ID}'&quot;
          deltaQuery=&quot;select ITEM_ID from FEATURE where last_modified &gt; '${dataimporter.last_index_time}'&quot;
          parentDeltaQuery=&quot;select ID from item where ID=${feature.ITEM_ID}&quot;&gt; 
    &lt;field name=&quot;features&quot; column=&quot;DESCRIPTION&quot; /&gt;
  &lt;/entity&gt;

  &lt;entity name=&quot;item_category&quot;
          query=&quot;select CATEGORY_ID from item_category where ITEM_ID='${item.ID}'&quot;
          deltaQuery=&quot;select ITEM_ID, CATEGORY_ID from item_category where last_modified &gt; '${dataimporter.last_index_time}'&quot;
          parentDeltaQuery=&quot;select ID from item where ID=${item_category.ITEM_ID}&quot;&gt;
    &lt;entity name=&quot;category&quot;
            query=&quot;select DESCRIPTION from category where ID = '${item_category.CATEGORY_ID}'&quot;
            deltaQuery=&quot;select ID from category where last_modified &gt; '${dataimporter.last_index_time}'&quot;
            parentDeltaQuery=&quot;select ITEM_ID, CATEGORY_ID from item_category where CATEGORY_ID=${category.ID}&quot;&gt;
      &lt;field column=&quot;description&quot; name=&quot;cat&quot; /&gt;
    &lt;/entity&gt;
  &lt;/entity&gt;
&lt;/entity&gt;

</document>
</dataConfig>




自用

<dataConfig>
  <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/shop?characterEncoding=utf-8" 
    user="root" password="root"/> 
  <document> 
	<entity name="item" query="select * from tb_item">
		<field  name="id" column="id" />
		<field name="item_title" column="title"/>
		<field name="item_sell_point" column="sell_point"/>
		<field name="item_price" column="price"/>
		<field name="item_image" column="image"/>
		<entity name = "category" query="select name from tb_item_cat where id = '${item.cid}'" >
			<field name="item_category_name" column="name" />    
		</entity>
	</entity>
  </document>
</dataConfig>

从D:\JAVA\code\solr-8.3.0\dist 里拷贝jar包到 D:\JAVA\code\solr-8.3.0\server\solr\new_core\lib
mysql-connector-java-5.1.32.jar solr-dataimporthandler-8.3.0.jar solr-dataimporthandler-extras-8.3.0.jar


重启

0

评论区