摘要:本文将带你了解WEBAPP开发教程Solr7.1搭建与整合(windows),希望本文对大家学WEBAPP有所帮助。
本文将带你了解WEBAPP开发教程Solr7.1搭建与整合(windows),希望本文对大家学WEBAPP有所帮助。
-版本solr-7.1.0
-环境 Windows jdk1.8
-框架 SSM
-启动方式:部署在apache-tomcat-8.5.23,以下简称Tomcat
1. 将solr-7.1.0\server\solr-webapp下的webapp复制到Tomcat\webapps下,并改名solr;
2. 将solr-7.1.0\server\lib下的ext下的所有jar包复制到Tomcat\webapps\solr\WEB-INF\lib下,以及
solr-7.1.0\server\lib下以metrics开头的jar、gmetric4j-1.0.7.jar复制到Tomcat\webapps\solr\WEB-INF\lib下;
3. 在Tomcat\webapps\solr\WEB-INF下创建classes文件夹,并把solr-7.1.0\server\resources下的log4.perportiy复制到 classes文件下;
4. 修改修改Tomcat\bin下的catalina.bat,增加solr.log.dir系统变量,指定solr日志记录存放地址。
if not "%JSSE_OPTS%" == "" goto gotJsseOptsset JSSE_OPTS="-Djdk.tls.ephemeralDHKeySize=2048":gotJsseOptsset "JAVA_OPTS=%JAVA_OPTS% %JSSE_OPTS%" --增加下一行set "JAVA_OPTS=%JAVA_OPTS% -Dsolr.log.dir=D:\Solr-7\solr_home\logs"
5. 在任意地方创建文件夹solr_home,把solr-7.1.0\server下solr下的所有文件复制到这个solr_home下,在这里,我创建在Solr-7.1.0的同级目录下了,并且修改配置文件Tomcat\webapps\solr\WEB-INF\web.xml,将下面配置的注释放开,黑体部分更改为你的solr-home地址。
<env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>D:\Solr-7\solr_home</env-entry-value> <env-entry-type>java.lang.String</env-entry-type></env-entry>
并注释下面部分:
<!-- Get rid of error message <security-constraint> <web-resource-collection> <web-resource-name>Disable TRACE</web-resource-name> <url-pattern>/</url-pattern> <http-method>TRACE</http-method> </web-resource-collection> <auth-constraint/> </security-constraint> <security-constraint> <web-resource-collection> <web-resource-name>Enable everything but TRACE</web-resource-name> <url-pattern>/</url-pattern> <http-method-omission>TRACE</http-method-omission> </web-resource-collection> </security-constraint>-->
6. 配合solr日志记录存放地址,在solr-home下新建logs文件夹,此处与配置4位置配置路径一致; 7. 拷贝solr-7.1.0下contrib和dist文件夹至solr-home目录下。 8. 在solr-home目录下新建new_core文件夹;并拷贝solr-7.1.0\server\solr\configsets_default\目录下conf文件夹至solr-home\new_core下。 9. 修改solr-home\new_core\conf\solrconfig.xml文件,如下
<!-- <lib dir="${solr.install.dir:../../../..}/contrib/extraction/lib" regex=".*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-cell-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/clustering/lib/" regex=".*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-clustering-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/langid/lib/" regex=".*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-langid-\d.*\.jar" /> <lib dir="${solr.install.dir:../../../..}/contrib/velocity/lib" regex=".*\.jar" /> <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-velocity-\d.*\.jar" /> --> <lib dir="${solr.install.dir:../}/contrib/extraction/lib" regex=".*\.jar" /> <lib dir="${solr.install.dir:../}/dist/" regex="solr-cell-\d.*\.jar" /> <lib dir="${solr.install.dir:../}/contrib/clustering/lib/" regex=".*\.jar" /> <lib dir="${solr.install.dir:../}/dist/" regex="solr-clustering-\d.*\.jar" /> <lib dir="${solr.install.dir:../}/contrib/langid/lib/" regex=".*\.jar" /> <lib dir="${solr.install.dir:../}/dist/" regex="solr-langid-\d.*\.jar" /> <lib dir="${solr.install.dir:../}/contrib/velocity/lib" regex=".*\.jar" /> <lib dir="${solr.install.dir:../}/dist/" regex="solr-velocity-\d.*\.jar" /> <lib dir="${solr.install.dir:../}/dist/" regex="ojdbc\d.*\.jar" /> <lib dir="${solr.install.dir:../}/dist/" regex="solr-dataimporthandler\d.*\.jar" />
10. 启动Tomcat,访问//localhost:8080/solr/index.html
11. 配置Ik分词器,首先导入ik的jar ik-analyzer-solr5-5.x 和 solr-analyzer-ik-5.1.0 两个jar包
导入Tomcat\webapps\solr\WEB-INF\lib下
然后配置solr_home\new_core\conf下的managed-schema文件加入
<fieldType name="text_ik" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> --此处为创建索引分词 <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> <analyzer type="query"> -- 此处为查询分词索引 <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true"/> <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType>
<field name="查询字段" type="text_ik" indexed="true" stored="true"/><field name="productName" type="text_ik" indexed="true" stored="true"/>
到此IK分词设置完成。
12. Solr与Spring整合
创建spring-context-solr.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="//www.springframework.org/schema/beans" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xmlns:context="//www.springframework.org/schema/context" xsi:schemaLocation=" //www.springframework.org/schema/beans //www.springframework.org/schema/beans/spring-beans-4.1.xsd //www.springframework.org/schema/context //www.springframework.org/schema/context/spring-context-4.1.xsd" default-lazy-init="true"> <!--定义solr的server--> <bean id="httpSolrClient" class="org.apache.solr.client.solrj.impl.HttpSolrClient"> <constructor-arg value="//location/solr/new_core"/> </bean></beans>
13. 创建测试类SorlJTest
@ContextConfiguration(locations = { "classpath*:/spring-context*.xml" }) public class SolrJTest extends AbstractTransactionalJUnit4SpringContextTests { private static final Log log = LogFactory.getLog(SolrJTest.class); @Autowired private HttpSolrClient client; @Test public void test() throws IOException, SolrServerException { SolrQuery solr = new SolrQuery(); solr.setQuery("productName:苹果"); QueryResponse queryResponse =client.query(solr); //拿到数据集合,返回查询结果 List<SolrDocument> list =queryResponse.getResults(); System.out.println(list); }}
14.有关IK分词,粗细力度查询
上面11中
useSmart="false" 为智能分词 false 关闭状态 默认最细力度分词
useSmart="true" 为智能分词 true 开启状态 默认最粗力度分词
智能分词的开关,根据自身业务的需求来进行设置,此处设置粗粒度查询 匹配度最高在第一位
15. 配置文件-自动导入数据库数据
在solr_home\new_core\conf下新建data-config.xml文件
<?xml version="1.0" encoding="UTF-8"?><dataConfig> <dataSource type="JdbcDataSource" driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@192.168.00.000:1521:XXXX" user="XXXXXX" password="XXXXXXX"/> <document><entity name="XXXXXX" pk="USERID" query="select NMSKY, NMSKY, USER_ID, USERNAM, USERRAT from XXXXXX" deltaQuery="select USER_ID as USERID from XXXXXX where to_char(TIME,'YYYY-MM-DD HH24:MI:SS') > '${dih.last_index_time}'" deltaImportQuery="select NMSKY,NMSKY,USER_ID,USERNAM,USERRAT from XXXXXX where USER_ID='${dih.delta.USERID}'"> </entity></document></dataConfig>
基本的配置就是这样了,如果有不对的地方请指教!
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之WebApp频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号