日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

将数据库表导入到solr索引

發布時間:2025/3/8 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 将数据库表导入到solr索引 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

將數據庫表導入到solr索引

  • 編輯solrcofnig.xml添加處理器

    <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"><lst name="defaults"><str name="config">data-config.xml</str></lst></requestHandler>
  • 創建一個名為data-config.xml的文件并保存如下內容到conf目錄(也就是solrconfig.xml的目錄)

    <dataConfig><dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/dbname" user="user-name" password="password"/><document><entity name="id" query="select id,name,desc from mytable"></entity></document></dataConfig>
  • 編輯schema.xml文件,保證文件中有'id','name','desc'等fields。并更改data-config.xml的詳細信息。

  • 將JDBC的jar驅動文件放到/lib文件夾中(tomcat/webapps/solr/WEB-INF/lib)

  • 運行命令 http://solr-host:port/solr/dataimport?command=full-import進行全量索引,每次進行全量索引時,會將數據清空,如果不想清空需要添加clean=false。例如http://solr-host:port/solr/dataimport?command=full-import&clean=false

  • 在字段名和field明不同的時候添加索引

  • 修改data-config.xml,如下所示

    <dataConfig><dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/dbname" user="user-name" password="password"/><document><entity name="id" query="select id,name,desc from mytable"><field column="id" name="solr_id"/><field column="name" name="solr_name"/><field column="desc" name="solr_desc"/></entity></document></dataConfig>
  • 寫入solr的字段為'solr_id', 'solr_name', solr_desc'。所以schema.xml中必須要要這幾個field。

  • 運行 http://solr-host:port/dataimpor?command=full-import 建立索引

  • 配置多個表建立索引

  • 修改data-config如下:

    <dataConfig><dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/dbname" user="user-name" password="password"/><document><entity name="outer" query="select id,name,desc from mytable"><field column="id" name="solr_id"/><field column="name" name="solr_name"/><field column="desc" name="solr_desc"/><entity name="inner"query="select details from another_table where id ='${outer.id}'"><field column="details" name="solr_details"/> </entity></entity></document></dataConfig>
  • schema.xml應該包含solr_details的字段

  • 運行full-import

  • mysql配置

  • 下載mysql的JDBC的jar,并拷貝到/lib的文件夾

  • 修改data-config為如下

    <dataConfig><dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://ip:3306/dbname" user="username" password="password"/> <document name="products"><entity ......</entity></document></dataConfig>
  • DataImportHandler支持的命令

    abort http://<host>:<port>/solr/dataimport?command=abort 終止命令 delta-import http://<host>:<port>/solr/dataimport?command=delta-import 增量 full-import http://<host>:<port>/solr/dataimport?command=full-import 全量 reload-config http://<host>:<port>/solr/dataimport?command=reload-config 重新加載配置 status http://<host>:<port>/solr/dataimport?command=status 狀態查詢

    總結

    以上是生活随笔為你收集整理的将数据库表导入到solr索引的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。