概述
一、搭建
1.1、下载 并 解压
tomcat
https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.54/bin/apache-tomcat-9.0.54-windows-x64.zip
solr 7.5
https://archive.apache.org/dist/lucene/solr/7.5.0/solr-7.5.0.zip
(这里为了简便我把tomcat命名为solr-tomcat)
1.2、将solr-7.5.0serversolr-webapp下的webapp文件夹及内容复制到solr-tomcatwebapps下,并改名为solr.
1.3、复制solr-7.5.0serverlibext下所有的jar到solr-tomcatwebappssolrWEB-INFlib
1.4、将solr-7.5.0serverlib路径下的名称为metrics开头的jar包复制到solr-tomcatwebappssolrWEB-INFlib路径下。
1.5、复制solr-7.5.0dist下solr-dataimporthandler-extras-7.5.0.jar、solr-dataimporthandler-7.5.0.jar到solr-tomcatwebappssolrWEB-INFlib。(导入数据所用的jar包)
1.6、复制solr-7.5.0serverresources下log4j2.xml 到 solr-tomcatwebappssolrWEB-INFclasses下(classes不存在的,就新建 )
1.7、新建solr-home文件夹,位置自定义,如:D:xxxsolr-home ,(这里就定义和tomcat在同一文件夹下)
1.8、将 solr-7.5.0serversolr下的内容复制到solr-home下
1.9、将 solr-7.5.0下的 contrib和 dist复制到solr-home下
1.10、 打开solr-tomcawebappssolrWEB-INF路径下的web.xml文件,添加配置solrHome ,value就是配置的solr-home的路径 这里路径可以是绝对路径也可以是相对路径
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>D:xxxsolr-home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
我这里配置了相对路径 (看个人要求)
同时注释掉下面的配置
<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>
1.11、配置solr日志。在D:xxx下新建文件夹logs (位置自定义),打开solr-tomcatbincatalina.bat,增加如下代码,path为刚刚新建的logs文件夹的路径
set "JAVA_OPTS=%JAVA_OPTS% -Dsolr.log.dir=D:xxxlogs"
我这里配置的路径是tomcat自带的logs(看个人要求)
set "JAVA_OPTS=%JAVA_OPTS% -Dsolr.log.dir=%CATALINA_HOME%logs"
现在solr基本上就搭建完成了 启动tomcat 就可以访问了
http://127.0.0.1:8080/solr/index.html
扩展 :
二、创建core
在solr-home文件夹下创建 solr-core文件夹(名字可自定义) 并复制solr-7.5.0serversolrconfigsets_default文件夹下的conf文件夹到 solr-core文件夹下
修改 conf文件夹下 solrconfig.xml 文件
重启solr
然后进入solr界面添加core
添加后就可以看到如下界面
三、配置导入功能
3.1在 solrconfig.xml文件中添加
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
3.2在solr-homesolr-coreconf 文件夹下新建data-config.xml文件
data-config.xml文件内容如下
<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@192.168.0.1:1521:credit" user="my" password="my"/>
<document>
<entity name="T_XZCF_TEST" pk="DATA_ID" query=" select 'T_XZCF_TEST' as TABLE_NAME , 'T_XZCF_TEST'||'-'||XYPTGUID as ID , XYPTGUID as DATA_ID, NAME as NAME, USCC as USCC, FR_ID as FR_ID, MAIN_SUBJECT as MAIN_SUBJECT, DATA_STATE as DATA_STATE, REPORT_DATE as REPORT_DATE from T_XZCF_TEST" deltaImportQuery=" select 'T_XZCF_TEST' as TABLE_NAME , 'T_XZCF_TEST'||'-'||XYPTGUID as ID , XYPTGUID as DATA_ID, NAME as NAME, USCC as USCC, FR_ID as FR_ID, MAIN_SUBJECT as MAIN_SUBJECT, DATA_STATE as DATA_STATE, REPORT_DATE as REPORT_DATE from T_XZCF_TEST where XYPTGUID = '${dih.delta.id}'" deltaQuery=" select 'T_XZCF_TEST' as TABLE_NAME , 'T_XZCF_TEST'||'-'||XYPTGUID as ID , XYPTGUID as DATA_ID, NAME as NAME, USCC as USCC, FR_ID as FR_ID, MAIN_SUBJECT as MAIN_SUBJECT, DATA_STATE as DATA_STATE, REPORT_DATE as REPORT_DATE from T_XZCF_TEST where REPORT_DATE > to_date('${dataimporter.last_index_time}','yyyy-mm-dd hh24:mi:ss')">
<field column="ID" name="id"/>
<field column="DATA_ID" name="solr_data_id"/>
<field column="NAME" name="solr_name"/>
<field column="USCC" name="solr_uscc"/>
<field column="FR_ID" name="solr_fr_id"/>
<field column="MAIN_SUBJECT" name="solr_main_subject"/>
<field column="DATA_STATE" name="solr_data_state"/>
<field column="REPORT_DATE" name="solr_report_date"/>
<field column="TABLE_NAME" name="solr_table_name"/>
</entity>
<entity name="T_XZXK_TEST" pk="DATA_ID" query=" select 'T_XZXK_TEST' as TABLE_NAME , 'T_XZXK_TEST'||'-'||XYPTGUID as ID , XYPTGUID as DATA_ID, NAME as NAME, USCC as USCC, FR_ID as FR_ID, MAIN_SUBJECT as MAIN_SUBJECT, DATA_STATE as DATA_STATE, REPORT_DATE as REPORT_DATE from T_XZXK_TEST" deltaImportQuery=" select 'T_XZXK_TEST' as TABLE_NAME , 'T_XZXK_TEST'||'-'||XYPTGUID as ID , XYPTGUID as DATA_ID, NAME as NAME, USCC as USCC, FR_ID as FR_ID, MAIN_SUBJECT as MAIN_SUBJECT, DATA_STATE as DATA_STATE, REPORT_DATE as REPORT_DATE from T_XZXK_TEST where XYPTGUID = '${dih.delta.id}'" deltaQuery=" select 'T_XZXK_TEST' as TABLE_NAME , 'T_XZXK_TEST'||'-'||XYPTGUID as ID , XYPTGUID as DATA_ID, NAME as NAME, USCC as USCC, FR_ID as FR_ID, MAIN_SUBJECT as MAIN_SUBJECT, DATA_STATE as DATA_STATE, REPORT_DATE as REPORT_DATE from T_XZXK_TEST where REPORT_DATE > to_date('${dataimporter.last_index_time}','yyyy-mm-dd hh24:mi:ss')">
<field column="ID" name="id"/>
<field column="DATA_ID" name="solr_data_id"/>
<field column="NAME" name="solr_name"/>
<field column="USCC" name="solr_uscc"/>
<field column="FR_ID" name="solr_fr_id"/>
<field column="MAIN_SUBJECT" name="solr_main_subject"/>
<field column="DATA_STATE" name="solr_data_state"/>
<field column="REPORT_DATE" name="solr_report_date"/>
<field column="TABLE_NAME" name="solr_table_name"/>
</entity>
</document>
</dataConfig>
3.3在solr-homesolr-coreconf文件夹下的managed-schema文件添加以前字段
<field name="solr_data_id" type="string" indexed="true" stored="true"/>
<field name="solr_uscc" type="string" indexed="true" stored="true"/>
<field name="solr_name" type="string" indexed="true" stored="true"/>
<field name="solr_table_name" type="string" indexed="true" stored="true"/>
<field name="solr_fr_id" type="string" indexed="true" stored="true"/>
<field name="solr_main_subject" type="pint" indexed="true" stored="true"/>
<field name="solr_data_state" type="pint" indexed="true" stored="true"/>
<field name="solr_report_date" type="pdate" indexed="true" stored="true"/>
注意这里的name一定要和data-config.xml中的name保持一致 (这里我自己所需的字段 你可以配置自己所需 )
把
或
数据库驱动放入solr-tomcatwebappssolrWEB-INFlib文件夹下 (导入所需的jar包已经在1.5执行过了)
重启solr
进入solr界面就可以通过表导入数据了
导入完成
接下来就可以查询数据了
恭喜你 已经完成了
四、配置中文分词器(这里配置的是solr自带的中文分词器)
4.1将solr-7.5.0contribanalysis-extraslucene-libs的jar 复制到 webapps/solr/WEB-INF/lib下
4.2 在solr-homesolr-coreconf 的managed-schema文件中添加
<fieldType name="solr_cnAnalyzer" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>
</analyzer>
</fieldType>
并修改其中一个字段 把type修改成solr_cnAnalyzer
重启
大功告成! 爽歪歪~
最后
以上就是陶醉马里奥为你收集整理的solr7.5.0部署到tomcat的全部内容,希望文章能够帮你解决solr7.5.0部署到tomcat所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复