solr8 0 從資料庫匯入資料(三)

2022-08-31 22:48:32 字數 3692 閱讀 9032

在建立的核心目錄下新建lib資料夾(如果有,無需建立),從solr原始碼包的dist資料夾中匯入兩個solr-dataimporthandler包,以及乙個mysql驅動包。

在檔案末尾新增以下內容

<

requesthandler

name

="/dataimport"

class

="org.apache.solr.handler.dataimport.dataimporthandler"

>

<

lst

name

="defaults"

>

<

str

name

="config"

>data-config.xml

str>

lst>

requesthandler

>

xml version="1.0" encoding="utf-8" 

?>

<

dataconfig

>

<

datasource

type

="jdbcdatasource"

driver

="com.mysql.jdbc.driver"

url="jdbc:mysql://localhost:3306/college_service"

user

="root"

password

="mysql"

/>

<

document

>

<

entity

name

="news"

query

="select * from news"

>

<

field

column

="news_id"

name

="id"

/>

<

field

column

="news_authorid"

name

="newsauthorid"

/>

<

field

column

="news_title"

name

="newstitle"

/>

<

field

column

="news_cover"

name

="newscover"

/>

<

field

column

="news_time"

name

="newstime"

/>

<

field

column

="news_browse"

name

="newsbrowse"

/>

<

field

column

="news_schoolid"

name

="newsschoolid"

/>

<

field

column

="news_categoryid"

name

="newscategoryid"

/>

<

field

column

="news_abstract"

name

="newsabstract"

/>

<

field

column

="news_content"

name

="newscontent"

/>

entity

>

document

>

dataconfig

>

然後在當前路徑的managed-schema檔案中加入相應的型別對映

<

field

name

="newsauthorid"

type

="string"

indexed

="true"

stored

="true"

/>

<

field

name

="newstitle"

type

="string"

indexed

="true"

stored

="true"

/>

<

field

name

="newscover"

type

="string"

indexed

="false"

stored

="true"

/>

<

field

name

="newstime"

type

="pdate"

indexed

="false"

stored

="true"

/>

<

field

name

="newsbrowse"

type

="pint"

indexed

="false"

stored

="true"

/>

<

field

name

="newsschoolid"

type

="string"

indexed

="false"

stored

="true"

/>

<

field

name

="newscategoryid"

type

="string"

indexed

="false"

stored

="true"

/>

<

field

name

="newsabstract"

type

="text_ik"

indexed

="true"

stored

="true"

/>

<

field

name

="newscontent"

type

="text_general"

indexed

="false"

stored

="true"

/>

登陸http://localhost:8983/solr/,進入以下模組,執行excute就匯入資料了,沒反應過來可以進行refresh status

solr系列二 solr匯入資料庫資料

2.找到d solr home catalog conf schema.xml來配置solr和資料庫的對應字段。uniquekey是文件的唯一標識,必須標識對應的字段,否則solr建立索引報錯。此處的field的name屬性最好和資料庫的字段保持一致,這樣我們可以減少一些對映配置。具體配置如下 ca...

solr的core匯入資料庫資料

準備材料資料庫指令碼 user itripdb drop table if exists itrip hotel create table itrip hotel id bigint 11 not null auto increment comment 主鍵 hotelname varchar 25...

solr連線資料庫匯入資料

本文簡單講訴 solr建立全文索引,從資料庫匯入資料,生成索引檔案,本文建立在已經搭建好solr應用的情況下,如要了解如何部署solr服務可先看上一文 solr 安裝 環境 jdk 7,solr4.10.1 tomcat 7 1,首先在solrconfig.xml中引入dataimport 路徑 e...