本文主要讲解solr和mysql数据库的链接
一、solr数据库连接
1、建立数据库表(mysql)
CREATE TABLE `test_person` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL COMMENT '姓名',
`description` varchar(500) DEFAULT NULL COMMENT '简介',
PRIMARY KEY (`id`)
);
insert into test_person(name,description) values('周星驰','香港著名喜剧演员');
insert into test_person(name,description) values('周润发','香港著名演员');
insert into test_person(name,description) values('周节能','台湾著名歌手,号称音乐天王');
insert into test_person(name,description) values('成龙','香港著名动作演员');
insert into test_person(name,description) values('山本一木','日本鬼子');
insert into test_person(name,description) values('仓木麻衣','日本歌手');
2、将数据库驱动文件加入solr的lib文件夹中
3、在自己创建的core实例的conf文件中进行数据配置(我的是\solr_home\solr\my_db\conf\dbdata-config.xml),覆盖内容如下(数据库表自己根据配置自己建):
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/solr" user="root" password="root" />
<document name="messages">
<entity name="message" transformer="ClobTransformer" query="select * from test_person where name like '%${dataimporter.request.name}%'">
<field column="id" name="id" />
<field column="name" name="name" />
<field column="description" name="description" />
</entity>
</document>
</dataConfig>
4、在\solr_home\solr\my_core\conf\schema.xml文件中添加如下字段信息(已存在则只需要在上面修改):
<field name="name" type="text_general" indexed="true" stored="true" multiValued="true" />
<field name="description" type="text_general" indexed="true" stored="true" multiValued="true" />