1 導入須要的驅動文件 mysql
2 在solrconfig.xml文件中添加sql
<!-- --> <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler>
3 在同級目錄下創建data-config.xml文件數據庫
4 在data-config.xml文件中添加數據庫配置apache
<?xml version="1.0" encoding="UTF-8" ?> <dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://129.0.0.1:3306/alphago_xj_1018_2" user="root" password="shiye"/> <document> <entity name="persionSHI" query="SELECT id,pr_name,pr_ethnic,pr_education,pr_jobcareer FROM ag_prisoner"> <field column="id" name="id" /> <field column="pr_name" name="prName" /> <field column="pr_ethnic" name="prEthnic"/> <field column="pr_education"name="prEducation"/> <field column="pr_jobcareer"name="prJobcareer"/> </entity> </document> </dataConfig>
5 在schema.xml文件中添加 上面對應的那麼的配置url
<!--field--> <field name="prName" type="string" indexed="true" stored="true"/> <field name="prEthnic" type="text_ik" indexed="true" stored="true"/> <field name="prEducation" type="text_ik" indexed="true" stored="true"/> <field name="prJobcareer" type="string" indexed="true" stored="true"/> <!----> <field name="persion_keywords" type="text_ik" indexed="true" stored="true" multiValued="true"/> <copyField source="prName" dest="persion_keywords"/> <copyField source="prJobcareer" dest="persion_keywords"/>