准备solr搭建搜索的学习笔记

一,安装部署solr

1. 下载tomcat解压,这里选择的是tomcat8

2. 下载solr最新版本(4.10.1)并解压solr文件夹下,下载地址是http://lucene.apache.org/solr/。 并将解压后solr\example\solr中的内容拷贝至的solrHome\下

3. 将solr解压后的solr\dist\solr-4.10.1.war 拷贝至apache-tomcat-8.0.12\webapps目录,并重命名为solr.war。

4. 在apache-tomcat-8.0.12\conf\server.xml中配置solr的Context,顺便修改端口号8080为80

1
2
3
< Context  path = "/solr"  docBase = "solr"  reloadable = "false"  crossContext = "true" >
    < Environment  name = "solr/home"  type = "java.lang.String"  value = "D:\workspace\develop\study\sorl_test\solrHome" />
</ Context >

5. 启动tomcat,并访问solr:http://localhost/solr,页面显示404,并在localhost日志中可以看到错误信息

1
2
3
4
5
6
7
8
SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter SolrRequestFilter 
java.lang.NoClassDefFoundError: Failed to initialize Apache Solr: Could not find necessary SLF4j logging jars. If using Jetty, the SLF4j logging jars need to go in the jetty lib/ext directory. For other containers, the corresponding directory should be used. For more information, see: http://wiki.apache.org/solr/SolrLogging 
at org.apache.solr.servlet.CheckLoggingConfiguration.check(CheckLoggingConfiguration.java:28) 
at org.apache.solr.servlet.BaseSolrFilter.<clinit>(BaseSolrFilter.java:31) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

6. 将solr\example\lib\ext下的jar文件件,拷贝至apache-tomcat-8.0.12\webapps\solr\WEB-INF\lib下

7. 重新启动,并访问solr

测试分词效果



二,为solr增加用户验证

1. 在tomcat的apache-tomcat-8.0.12\conf\tomcat-users.xml 添加用户角色并指定访问的用户名密码

1
2
< role  rolename = "solr" />
< user  username = "solr"  password = "52menshao"  roles = "solr" />

2. 在apache-tomcat-8.0.12\webapps\solr\WEB-INF\web.xml中添加用户访问权限设置 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
< security-constraint >
       < web-resource-collection >
           < web-resource-name >Solr Lockdown</ web-resource-name >
           < url-pattern >/</ url-pattern >
           < http-method >GET</ http-method >
           < http-method >POST</ http-method >
       </ web-resource-collection >
       < auth-constraint >
           < description >This applies only to the "tomcat" security role</ description >
           < role-name >solr</ role-name >
           < role-name >admin</ role-name >
       </ auth-constraint >
       < user-data-constraint >
           < transport-guarantee >NONE</ transport-guarantee >
       </ user-data-constraint >
   </ security-constraint >
  
   < login-config >
       < auth-method >BASIC</ auth-method >
       < realm-name >Solr</ realm-name >
   </ login-config >


三、为solr添加中文分词

 1. 在不做任何改动的情况下,做中文分词如下


2. 此次为solr进行中文分词,选择的组件是mmseg4j,开源地址是:https://github.com/chenlb/mmseg4j-solr

     mmseg4j支持最多分词,是一款很优秀的中文分词器,是用Chih-Hao Tsai 的 MMSeg 算法( http://technology.chtsai.org/mmseg/ )实现的中文分词器,并实现 lucene 的analyzer 和 solr 的TokenizerFactory 以方便在Lucene和Solr中使用。 

3. 下载中文分词需要依赖的jar包,放于apache-tomcat-8.0.12\webapps\solr\WEB-INF\lib下

      1. mmseg4j-for-solr(mmseg4j-solr-2.2.0.jar)           2. mmseg4j-core(mmseg4j-core-1.10.0.jar)

4.  修改solr_home\collection1\conf\schema.xml,

     4.1 添加如下代码,代码片段可以从https://github.com/chenlb/mmseg4j-solr中直接拷贝,可修改dicPath 参数 - 设置自定义的扩展词库,支持相对路径(相对于 solr_home).


     4.2 更改原有配置,使原有一些重要的字段从英文分词器换成中文分词器,使之支持中文分词


5. 重启tomcat查看效果

四、 Solr后台的使用

     略,这里可以自己先了解一下,功能一目了然

五、SorlJ的使用

 添加solrj的jar文件

1
2
3
4
5
< dependency >
     < groupId >org.apache.solr</ groupId >
     < artifactId >solr-solrj</ artifactId >
     < version >4.10.1</ version >
   </ dependency >



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值