本教程是从别人的基础上借鉴整理的
一、solr安装
<env-entry><env-entry-name>solr/home</env-entry-name><env-entry-value>D:/testsolr/solr_home/solr</env-entry-value><env-entry-type>java.lang.String</env-entry-type></env-entry>
二、创建第一个core
三、solr分词
<fieldtype name=“textComplex” class=“solr.TextField” positionIncrementGap=“100”><analyzer><tokenizer class=“com.chenlb.mmseg4j.solr.MMSegTokenizerFactory” mode=“complex” dicPath=“D:/testsolr/solr_home/solr/dic”>
tokenizer>
analyzer>
fieldtype><fieldtype name=“textMaxWord” class=“solr.TextField” positionIncrementGap=“100”><analyzer><tokenizer class=“com.chenlb.mmseg4j.solr.MMSegTokenizerFactory” mode=“maxword” dicPath=“D:/testsolr/solr_home/solr/dic”>
tokenizer>
analyzer>
fieldtype><fieldtype name=“textSimple” class=“solr.TextField” positionIncrementGap=“100”><analyzer><tokenizer class=“com.chenlb.mmseg4j.solr.MMSegTokenizerFactory” mode=“simple” dicPath=“D:/testsolr/solr_home/solr/dic”>
tokenizer>
analyzer>
fieldtype>
"name"
type=
"textMaxWord" indexed=
"true" stored=
"true" multiValued=
"true" />
"description"
type=
"textMaxWord" indexed=
"true" stored=
"true" multiValued=
"true" />
- 1
- 2
- 1
- 2
四、solr连接数据库
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('仓木麻衣','日本歌手');
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
<dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user="root" password="jhp123" /> <document name="messages"> <entity name="message" transformer="ClobTransformer" query="select * from test_peoson where name like '%${dataimporter.request.name}%'"> <field column="id" name="id" /> <field column="name" name="name" /> <field column="description" name="description" />
entity>
document>
dataConfig>
url=”jdbc:mysql://localhost:3306/test” user=”root” password=”123” 这里配置了 mysql 的连接路径 , 用户名 , 密码
"name"
name=
"name" /> 这里配置的是数据库里要索引的字段, 注意
name是在分词的第
4 步配置的,同时只有这样匹配的字段最终solr才会查询显示出来,所以需要用到的字段必须在该文件中
"*"
name=
"*" />配置才可以;
- 1
- 1
3、在D:\testsolr\solr_home\solr\my_core\conf\schema.xml文件中添加如下字段信息:
"name"
type=
"textMaxWord" indexed=
"true" stored=
"true" multiValued=
"true" />
"description"
type=
"textMaxWord" indexed=
"true" stored=
"true" multiValued=
"true" />
- 1
- 2
- 1
- 2
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">D:/testsolr/solr_home/solr/my_core/conf/solr-data-config.xml
str>
lst>
requestHandler>
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
solr查询参数具体参考:http://www.cnblogs.com/zhangweizhong/p/5056884.html
solr在Java中的使用:http://blog.csdn.net/u0/article/details/
一、solr安装
<env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>D:/testsolr/solr_home/solr</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry>
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
二、创建第一个core
三、solr分词
<fieldtype name="textComplex" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" dicPath="D:/testsolr/solr_home/solr/dic">
tokenizer>
analyzer>
fieldtype> <fieldtype name="textMaxWord" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="maxword" dicPath="D:/testsolr/solr_home/solr/dic">
tokenizer>
analyzer>
fieldtype> <fieldtype name="textSimple" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" dicPath="D:/testsolr/solr_home/solr/dic">
tokenizer>
analyzer>
fieldtype>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
"name"
type=
"textMaxWord" indexed=
"true" stored=
"true" multiValued=
"true" />
"description"
type=
"textMaxWord" indexed=
"true" stored=
"true" multiValued=
"true" />
- 1
- 2
- 1
- 2
四、solr连接数据库
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('仓木麻衣','日本歌手');
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
<dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user="root" password="jhp123" /> <document name="messages"> <entity name="message" transformer="ClobTransformer" query="select * from test_peoson where name like '%${dataimporter.request.name}%'"> <field column="id" name="id" /> <field column="name" name="name" /> <field column="description" name="description" />
entity>
document>
dataConfig>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
url=”jdbc:mysql://localhost:3306/test” user=”root” password=”123” 这里配置了 mysql 的连接路径 , 用户名 , 密码
"name"
name=
"name" /> 这里配置的是数据库里要索引的字段, 注意
name是在分词的第
4 步配置的,同时只有这样匹配的字段最终solr才会查询显示出来,所以需要用到的字段必须在该文件中
"*"
name=
"*" />配置才可以;
- 1
- 1
3、在D:\testsolr\solr_home\solr\my_core\conf\schema.xml文件中添加如下字段信息:
"name"
type=
"textMaxWord" indexed=
"true" stored=
"true" multiValued=
"true" />
"description"
type=
"textMaxWord" indexed=
"true" stored=
"true" multiValued=
"true" />
- 1
- 2
- 1
- 2
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">D:/testsolr/solr_home/solr/my_core/conf/solr-data-config.xml
str>
lst>
requestHandler>
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
solr查询参数具体参考:http://www.cnblogs.com/zhangweizhong/p/5056884.html
solr在Java中的使用:http://blog.csdn.net/u0/article/details/
转载于:https://www.cnblogs.com/juochiu/p/6250425.html
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/220809.html原文链接:https://javaforall.net
