一、參照 http://www.cnblogs.com/luxh/p/5016894.html 部署好solr的環境html
二、在solr_home下創建一個core_item目錄java
[root@iZ23exixsjaZ solr_home]# pwd /luxh/solr/solr_home [root@iZ23exixsjaZ solr_home]# mkdir core_item
在core_item目錄中創建data目錄mysql
[root@iZ23exixsjaZ core_item]# pwd /luxh/solr/solr_home/core_item [root@iZ23exixsjaZ core_item]# mkdir data
三、將/luxh/solr/solr-5.3.1/example/example-DIH/solr/db路徑下的conf目錄拷貝到剛纔建立的core_item目錄中web
[root@iZ23exixsjaZ data_driven_schema_configs]# pwd /luxh/solr/solr-5.3.1/example/example-DIH/solr/db [root@iZ23exixsjaZ data_driven_schema_configs]# cp -r conf /luxh/solr/solr_home/core_item
四、在solr管理界面配置添加一個coresql
五、拷貝相應的jar包到solr項目中數據庫
拷貝mysql-connector-java-5.1.37.jar和solr-dataimporthandler-5.3.1.jar到solr項目中apache
拷貝路徑:tomcat
/luxh/solr/apache-tomcat-8.0.29/webapps/solr/WEB-INF/lib
六、配置solrconfig.xml,加入solr數據導入處理器(其實從solr拷貝過來的文件已經配置好了)app
<requestHandler name="/dataimport" class="solr.DataImportHandler"> <lst name="defaults"> <str name="config">db-data-config.xml</str> </lst> </requestHandler>
七、配置db-data-config.xml,加入鏈接數據庫的信息,按本身的實際字段配置webapp
<dataConfig> <dataSource name="testDB" type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/fashion?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf8&autoReconnect=true" user="root" password="root" /> <document> <entity name="item" query="select * from item"> <field column="Uuid" name="id"/> <field column="ShopId" name="ShopId"/> <field column="Cat" name="Cat"/> <field column="Building" name="Building"/> <field column="Floor" name="Floor"/> <field column="Position" name="Position"/> <field column="Title" name="Title"/> <field column="Price" name="Price"/> <field column="Color" name="Color"/> <field column="Size" name="Size"/> <field column="Input_str" name="Input_str"/> </entity> </document> </dataConfig>
column表示數據庫中的列;name是solr的schema.xml配置的field的name
八、配置solr的schema.xml,加入一下內容:
<field name="ShopId" type="int" indexed="false" stored="true"/> <field name="Cat" type="text_ansj" indexed="true" stored="true"/> <field name="Building" type="text_ansj" indexed="true" stored="true"/> <field name="Floor" type="int" indexed="false" stored="true"/> <field name="Position" type="text_ansj" indexed="true" stored="true"/> <field name="Title" type="text_ansj" indexed="true" stored="true"/> <field name="Price" type="float" indexed="true" stored="true"/> <field name="Color" type="text_ansj" indexed="true" stored="true"/> <field name="Input_str" type="text_ansj" indexed="true" stored="true"/> <field name="Size" type="text_ansj" indexed="true" stored="true"/> <field name="allwords" type="text_ansj" indexed="true" stored="false" multiValued="true"/> <copyField source="Cat" dest="allwords"/> <copyField source="Title" dest="allwords"/> <copyField source="Color" dest="allwords"/> <copyField source="Input_str" dest="allwords"/> <copyField source="Size" dest="allwords"/>
九、配置好中文分詞器
參照 http://www.cnblogs.com/luxh/p/5017336.html
十、啓動tomcat
十一、導入數據
十二、若是日誌中有SolrResourceLoader Can't find (or read) directory to add to classloader: ../../../contrib/extraction/lib等找不到庫的警告,
主要是找不到solr安裝目錄中的solr-5.3.1/contrib和 solr-5.3.1/dist. 則在solrconfig.xml中指定這兩個目錄的路徑便可
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/extraction/lib" regex=".*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-cell-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/clustering/lib/" regex=".*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-clustering-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/langid/lib/" regex=".*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-langid-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/velocity/lib" regex=".*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-velocity-\d.*\.jar" /> 替換爲: <lib dir="/luxh/solr/solr_home/dist/" regex="solr-dataimporthandler-.*\.jar" /> <lib dir="/luxh/solr/solr_home/contrib/extraction/lib" regex=".*\.jar" /> <lib dir="/luxh/solr/solr_home/dist/" regex="solr-cell-\d.*\.jar" /> <lib dir="/luxh/solr/solr_home/contrib/clustering/lib/" regex=".*\.jar" /> <lib dir="/luxh/solr/solr_home/dist/" regex="solr-clustering-\d.*\.jar" /> <lib dir="/luxh/solr/solr_home/contrib/langid/lib/" regex=".*\.jar" /> <lib dir="/luxh/solr/solr_home/dist/" regex="solr-langid-\d.*\.jar" /> <lib dir="/luxh/solr/solr_home/contrib/velocity/lib" regex=".*\.jar" /> <lib dir="/luxh/solr/solr_home/dist/" regex="solr-velocity-\d.*\.jar" />