一 solr5.5環境部署到Eclipse(luna版)
solr部署參見:http://blog.csdn.net/csmnjk/article/details/64121765
二 Ik分詞器設置
IK分詞器設置參見:http://blog.csdn.net/csmnjk/article/details/51693578
solr4版本的schema.xml文件對應solr5版本的managed-schema文件,確保http://localhost:8080/solr/admin.html登陸成功。
三 MySQl配置
1. 連接MYSQL數據庫需要兩個jar包:solr-dataimporthandler-5.5.0 jar和mysql-connector-java-5.1.40-bin.jar。前一個包在solr-5.5.0/dist中,后一個包http://download.csdn.net/download/u012453843/9667329點擊下載。
2. 創建表
create table `article` ( `id` int unsigned not null auto_increment comment '主鍵編號', `title` varchar(64) not null comment '書名', `author`varchar(10) not null default 0 comment '作者', `type`varchar(10) not null default 0 comment '類型', primary key (`id`)) engine = innodb auto_increment = 1 default character set = utf8 ;

3. 配置文件
(1)在solrHome\core\conf中的solrcong.xml文件下新增如下配置
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
並注釋以下代碼:
<schemaFactory class="ManagedIndexSchemaFactory">
<bool name="mutable">true</bool>
<str name="managedSchemaResourceName">managed-schema</str>
</schemaFactory>
(2)在conf文件夾下新建data-config.xml文件,並添加如下配置
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test" user="root" password="password" />
<document name="article">
<entity name="article" pk="id"
query="select * from article"
deltaImportQuery="select * from article where id ='${dih.delta.id}'"
deltaQuery="select id from article where timestamp > '${dih.last_index_time}'">
</entity>
</document>
</dataConfig>
說明:user: MySQL用戶名, password:MySQL登錄密碼,test:數據庫名, article:表名。
(3)在其他地方備份managed-schema,將其改名為schema.xml。添加索引字段配置
<field name="title" type="text_ik" indexed="true" stored="true" multiValued="true" /> <field name="description" type="text_ik" indexed="true" stored="true" /> <field name="author" type="text_ik" indexed="true" stored="true" />
至此配置完成!
四 啟動solr

core0->Dataimport->full-import->Execute,執行之后點下Refresh Status,右邊就會顯示索引信息。
查詢驗證下:

表中的四條數據全被索引並成功查詢。
