Docker+Solr+IK 朴灿烈づ我的快乐病毒、 2022-05-16 02:34 105阅读 0赞 1. docker安装solr docker pull solr 1. 启动solr镜像 docker run -d -p 8983:8983 --name mysolr solr 1. run 运行容器 2. -d 代表后台运行 3. -p 容器端口和宿机端口映射 4. --name 容器名称 5. solr 镜像名称 1. 新建core docker exec -it --user=solr mysolr bin/solr create_core -c ik_core 1. 进入solr容器 docker exec -it -u root mysolr /bin/bash 1. 安装vim(编辑容器里的文件) apt-get update apt-get install vim 1. 安装rzsz(上传下载容器里的文件) apt-get install lrzsz 1. 进入/opt/solr/server/solr-webapp/webapp/WEB-INF/lib添加jar包 ik-analyzer-7.4.0.jar mysql-connector-java-8.0.11.jar solr-dataimporthandler-7.4.0.jar solr-dataimporthandler-extras-7.4.0.jar 1. 进入/opt/solr/server/solr/ik\_core/conf,新建data-config.xml <?xml version="1.0" encoding="UTF-8"?> <dataConfig> <dataSource name="source1" type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://***.**.**.**:3306/*****" user="****" password="******" batchSize="-1" /> <document> <entity name="service_info" dataSource="source1" query="SELECT id,title,business_type_id,category_id , service_price , service_time,service_desc,service_area, cover,click_count,create_by,create_date,del_flag FROM service_info where del_flag = 1"> <field column='id' name='id' /> <field column='title' name='title' /> <field column='business_type_id' name='business_type_id' /> <field column='category_id' name='category_id' /> <field column='service_price' name='service_price' /> <field column='service_time' name='service_time' /> <field column='service_desc' name='service_desc' /> <field column='service_area' name='service_area' /> <field column='cover' name='cover' /> <field column='click_count' name='click_count' /> <field column='create_by' name='create_by' /> <field column='create_date' name='create_date' /> <field column='del_flag' name='del_flag' /> </entity> </document> </dataConfig> 1. 配置managed-schema,加入IK分词 <!-- ik分词器 --> <fieldType name="text_ik" class="solr.TextField"> <analyzer type="index" useSmart="false" class="org.wltea.analyzer.lucene.IKAnalyzer" /> <analyzer type="query" useSmart="true" class="org.wltea.analyzer.lucene.IKAnalyzer" /> </fieldType> <field name='id' type="string" indexed="true" stored="true"/> <field name='title' type="text_ik" indexed="true" stored="true" omitNorms = "false" omitTermFreqAndPositions ="false"/> <field name='business_type_id' type="string" indexed="true" stored="true"/> <field name='category_id' type="string" indexed="true" stored="true"/> <field name='service_price' type="string" indexed="true" stored="true"/> <field name='service_time' type="string" indexed="true" stored="true"/> <field name='service_desc' type="text_ik" indexed="true" stored="true"/> <field name='service_area' type="text_ik" indexed="true" stored="true"/> <field name='cover' type="string" indexed="true" stored="true"/> <field name='click_count' type="string" indexed="true" stored="true"/> <field name='create_by' type="string" indexed="true" stored="true"/> <field name='create_date' type="string" indexed="true" stored="true"/> <field name='del_flag' type="string" indexed="true" stored="true"/> 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> 1. 重启solr容器 docker restart 45b022b95c71
还没有评论,来说两句吧...