solr搭建搜索
http://www.52menshao.com/content/1122一,安装部署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
<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日志中可以看到错误信息
SEVERE 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 添加用户角色并指定访问的用户名密码
<role rolename="solr"/>
<user username="solr" password="52menshao" roles="solr"/>
2. 在apache-tomcat-8.0.12\webapps\solr\WEB-INF\web.xml中添加用户访问权限设置
<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文件
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.10.1</version>
</dependency>
页:
[1]