solr-4.10.4环境搭建+导入数据库+中文分词
2016-02-20 15:29
316 查看
solr配置
1.安装java
2.安装tomcat
注意,修改tomcat的字符编码:
3.将solr-4.10.4.zip压缩包解压
4.将exmaple/webapps中的solr.war包解压开复制到Tomcat的webapps中,
或者直接将solr.war包直接复制到Tomcat的webapps中,
复制example/lib/ext目录中的jar包放到webapps/solr/WEB-INF/lib下
设置日志,将example/resources/log4j.properties也拷
webapps/solr/WEB-INF/lib/classes目录,classes需要自行创建,
这里要注意,这个properties中的配置为:
然后启动Tomcat使
其解压开再将war包删除
5.将example/solr目录拷贝到solrhome 文件夹中,并重命名为solrhome
6.设置solrhome 打开solr/WEB-INF/web.xml文件,找到env-entry
7.注意
linux:
ik配置
1.下载ik :ik-analyzer(中文分词工具包)
http://git.oschina.net/wltea/IK-Analyzer-2012FF
2.解压后,将IKAnalyzer2012FF_u1.jar拷贝到:
webapps/solr/WEB-INF/lib
3.将IKAnalyzer.cfg.xml和stopword.dic拷贝到:solr_home/core0(或collection1)/conf
4.修改schema.xml,添加:
5.重启tomcat
导入数据库数据:
1.solrconfig.xml 配置
使用DataImportHandler导入并索引数据
2.导入jar和数据库驱动包,放到webapps/solr/WEB-INF/lib
solr-dataimporthandler-4.10.4.jar
solr-dataimporthandler-extras-4.10.4.jar
数据库驱动包
3.E:\solrhome\collection1\conf 下创建db文件夹,创建文件:db-data-config.xml
4 修改schema.xml,这是Solr对数据库里的数据进行索引的模式
(1)保留version 这个field
(2)添加索引字段:这里每个field的name要和db-data-config.xml里的entity的field的name一样,一一对应。
5 删除多余的field,删除copyField里的设置,注意:text这个field不能删除,否则Solr启动失败。
6 设置唯一主键:id,注意:Solr中索引的主键默认
是只支持type=”string”字符串类型的,而如果数据库中id是int型的,会有问题,解决方法:修改同目录下的elevate.xml,注释掉下面2行,这貌似是Solr的Bug,原因不明。
7 重启Solr,如果配置正确就可以启动成功。
8.点击Dataimport,Command选择full-import(默认),点击“Execute”,Refresh Status就可以看到结果
1.安装java
2.安装tomcat
注意,修改tomcat的字符编码:
3.将solr-4.10.4.zip压缩包解压
4.将exmaple/webapps中的solr.war包解压开复制到Tomcat的webapps中,
或者直接将solr.war包直接复制到Tomcat的webapps中,
复制example/lib/ext目录中的jar包放到webapps/solr/WEB-INF/lib下
设置日志,将example/resources/log4j.properties也拷
webapps/solr/WEB-INF/lib/classes目录,classes需要自行创建,
这里要注意,这个properties中的配置为:
/** log4j.appender.file.File=${solr.log}/solr.log, solr.log为tomcat启动时指定的变量,如果没指定,日志文件可能会写到其他目录下。其实这里直接写成绝对路径也是不错的选择。 **/
然后启动Tomcat使
其解压开再将war包删除
5.将example/solr目录拷贝到solrhome 文件夹中,并重命名为solrhome
6.设置solrhome 打开solr/WEB-INF/web.xml文件,找到env-entry
<!-- solr home文件位置 --> <env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>E:\solrhome</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry>
7.注意
linux:
1.vi /opt/tomcat/conf/server.xml 2.cp solr-4.5.0/dist/solr-4.5.0.war /opt/tomcat/webapps/solr.war 3.vi /opt/tomcat/webapps/solr/WEB-INF/web.xml 4.solr4.3+的war包中不包含任何日志的jar包,你需要自己手动添加 5. cp solr-4.5.0/example/lib/ext/* /opt/tomcat/webapps/solr/WEB-INF/lib/ 6. mkdir /opt/tomcat/webapps/solr/WEB-INF/classes/ 7. cp solr-4.5.0/example/resources/log4j.properties /opt/tomcat/webapps/solr/WEB-INF/classes/
ik配置
1.下载ik :ik-analyzer(中文分词工具包)
http://git.oschina.net/wltea/IK-Analyzer-2012FF
2.解压后,将IKAnalyzer2012FF_u1.jar拷贝到:
webapps/solr/WEB-INF/lib
3.将IKAnalyzer.cfg.xml和stopword.dic拷贝到:solr_home/core0(或collection1)/conf
4.修改schema.xml,添加:
<!--- 配置中文分词器--> <fieldtype name="text_ik" class = "solr.TextField"> <analyzer type="index" inMaxWordLength="true" class ="org.wltea.analyzer.lucene.IKAnalyzer" /> <analyzer type="query" inMaxWordLength="true" class ="org.wltea.analyzer.lucene.IKAnalyzer" /> </fieldtype>
5.重启tomcat
导入数据库数据:
1.solrconfig.xml 配置
使用DataImportHandler导入并索引数据
<!-- 添加数据库导入功能 --> <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">E:\solrhome\collection1\conf\db\db-data-config.xml</str> </lst> </requestHandler>
2.导入jar和数据库驱动包,放到webapps/solr/WEB-INF/lib
solr-dataimporthandler-4.10.4.jar
solr-dataimporthandler-extras-4.10.4.jar
数据库驱动包
3.E:\solrhome\collection1\conf 下创建db文件夹,创建文件:db-data-config.xml
<dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1/goods" user="root" password="root"/> <document name="goods"> <entity name="book" transformer="ClobTransformer" pk="bid" query="select bid,bname,author,price,currprice,discount,press,publishtime,edition,pagenum,wordnum,printtime,booksize,paper from t_book"> <field column="bid" name="id" /> 必须为id <field column="bname" name="bname"/> <field column="author" name="bauthor"/> <field column="price" name="bprice"/> <field column="currprice" name="bcurrprice"/> <field column="discount" name="bdiscount"/> <field column="press" name="bpress"/> <field column="publishtime" name="bpublishtime"/> <field column="edition" name="bedition"/> <field column="pagenum" name="bpagenum"/> </entity> </document> </dataConfig> <!-- 说明: dataSource是数据库数据源。 Entity就是一张表对应的实体,pk是主键,query是查询语句。 Field对应一个字段,column是数据库里的column名, 后面的name属性对应着Solr的Filed的名字。 -->
4 修改schema.xml,这是Solr对数据库里的数据进行索引的模式
(1)保留version 这个field
(2)添加索引字段:这里每个field的name要和db-data-config.xml里的entity的field的name一样,一一对应。
<field name="_version_" type="long" indexed="true" stored="true"/> <!-- 数据库字段配置: --> <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="bname" type="text_ik" indexed="true" stored="true" multiValued="true"/> <field name="bauthor" type="text_ik" indexed="true" stored="true" multiValued="true"/> <field name="bprice" type="text_ik" indexed="true" stored="true" multiValued="true"/> <field name="bcurrprice" type="text_ik" indexed="true" stored="true" multiValued="true"/> <field name="bdiscount" type="text_ik" indexed="true" stored="true" multiValued="true"/> <field name="bpress" type="text_ik" indexed="true" stored="true" multiValued="true"/> <field name="bpublishtime" type="text_ik" indexed="true" stored="true" multiValued="true"/> <field name="bedition" type="text_ik" indexed="true" stored="true" multiValued="true"/> <field name="bpagenum" type="text_ik" indexed="true" stored="true" multiValued="true"/> <uniqueKey>id</uniqueKey>
5 删除多余的field,删除copyField里的设置,注意:text这个field不能删除,否则Solr启动失败。
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
6 设置唯一主键:id,注意:Solr中索引的主键默认
是只支持type=”string”字符串类型的,而如果数据库中id是int型的,会有问题,解决方法:修改同目录下的elevate.xml,注释掉下面2行,这貌似是Solr的Bug,原因不明。
<doc id="MA147LL/A" /> <doc id="IW-02" exclude="true" />
7 重启Solr,如果配置正确就可以启动成功。
solrconfig.xml是solr的基础文件,里面配置了各种web请求处理器、请求响应处理器、日志、缓存等。 schema.xml配置映射了各种数据类型的索引方案。分词器的配置、索引文档中包含的字段也在此配置。
8.点击Dataimport,Command选择full-import(默认),点击“Execute”,Refresh Status就可以看到结果
相关文章推荐
- hibernate,mybatis,beetlsql 全面比较
- 关于mysql下载后没有my.ini文件解决方案
- oracle中split的使用
- MySQL知识(七)——聚合函数、加密函数
- mysql常用命令
- 经典SQL语句大全
- 如何在 Go 语言中使用 Redis 连接池-Radix.v2
- 如何在SQLServer中处理每天四亿三千万记录的
- Schemaless架构(二):Uber基于MySQL的Trip数据库
- 【解决】MySql 5.6 运行崩溃错误
- sql事务(Transaction)用法介绍及回滚实例
- oracle数据库学习 (上)
- Redis的安装与配置
- 允许ubuntu下mysql远程连接
- Redis简介、Redis安装
- 【Mubatis】批量更新
- MySQL知识(六)——时间日期函数、系统信息函数
- mysql忘记root密码如何修改
- 查看sqlserver 2008中性能低下的语句
- 【Linux运维入门】Linux环境编译安装、配置Mysql