How to install Solr 8.6.2 in Docker and configure the Chinese word segmenter

How to install Solr 8.6.2 in Docker and configure the Chinese word segmenter

1. Environment version

Docker version 19.03.12

centos7

solr8.6.2

2. Docker installation

1. Automatically install using the official installation script

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

2. Use the domestic daocloud one-click installation command:

curl -sSL https://get.daocloud.io/docker | sh

3. Install solr8.6.2 in docker 1. Pull solr in docker

docker pull solr

2. Create and enable the Solr container

docker run --name blog-solr -d -p 8983:8983 solr // blog-solr can be named by yourself

// Parameter details

Run the container
-d Run in the background
-p container port and host port mapping – name container name
blog-solr refers to the image name

3. Create the core

docker exec -it --user=solr blog-solr bin/solr create_core -c Ik_core 

insert image description here

The Created new core 'Ik_core' message appears, which means that more than

4. Browser access

Enter IP:8983 in the browser to access my server.

insert image description here

5. Solr configures Chinese word segmenter 5.2 Download Ik file

Link: https://pan.baidu.com/s/1pkI9ZCThkDdzj4MWg3MO9A Extraction code: pgv8

 // 創建創建個目錄將解壓的文件放在這里mkdir /mnt/Ik/

insert image description here

5.2 Copy the configuration file

docker cp ik-analyzer-8.3.0.jar blog-solr:/opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/
docker cp ik-analyzer-solr7-7.x.jar blog-solr:/opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/
docker cp solr-dataimporthandler-8.4.0.jar blog-solr:/opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/
docker cp solr-dataimporthandler-extras-8.4.0.jar blog-solr:/opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/

Enter the solr container and create a folder

docker exec -it --user=root blog-solr /bin/bash
cd /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF
mkdir classes
exit
docker cp IKAnalyzer.cfg.xml blog-solr:/opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/classes/

5.3 IKAnalyzer.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">

<properties>
	<comment>IK Analyzer Extended Configuration</comment>
		<!--Users can configure their own extended dictionary here-->
	<entry key="ext_dict">ext.dic;</entry>
		<!--Users can configure their own extended stop word dictionary here-->
	<entry key="ext_stopwords">stopword.dic;</entry>
</properties>

5.4 Modify managed-schema

docker exec -it --user=root blog-solr /bin/bash
cp /opt/solr-8.6.2/contrib/analysis-extras/lucene-libs/lucene-analyzers-smartcn-8.6.2.jar /opt/solr-8.6.2/server/solr-webapp/webapp/WEB-INF/lib/
cd /var/solr/data/Ik_core/conf
vim managed-schema

If you don't have vim, you can use vi or install it using apt-get install vim

Add at the bottom:

<!-- ik word segmenter -->
 <fieldType name="text_ik" class="solr.TextField">
	 <analyzer type="index">
		 <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
		 <filter class="solr.LowerCaseFilterFactory"/>
	 </analyzer>
	 <analyzer type="query">
		 <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
		 <filter class="solr.LowerCaseFilterFactory"/>
	 </analyzer>
 </fieldType>

 <fieldType name="text_cn" 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> 

insert image description here

5.5 Modify solrconfig.xml

Add at the bottom

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> 
 <lst name="defaults">
  <str name="config">db-data-config.xml</str> 
 </lst> 
</requestHandler> 

insert image description here

Restart Solr

exit
docker restart blog-solr

4. Testing

1. Check whether the word segmenter is configured successfully

insert image description here

2. Test whether the word segmenter can segment words normally

insert image description here

3. Test the search function

insert image description here

This is the end of this article about how to install Solr 8.6.2 in Docker and configure the Chinese word segmenter. For more information about configuring the Chinese word segmenter in Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Java implements simple word segmentation function
  • Detailed explanation of deploying Elasticsearch kibana and ik word segmenter in docker
  • How to install kibana tokenizer inside docker container
  • How to install elasticsearch-analysis-ik Chinese word segmenter
  • Solr implements custom word segmentation through special characters
  • How to implement a powerful Chinese word segmenter in iOS
  • JAVA StringBuffer class and StringTokenizer class code analysis
  • Detailed explanation of the StringTokenizer class in Java (recommended)
  • A brief talk about Tokenizer

<<:  A detailed guide to custom directives in Vue

>>:  How to query whether the mysql table is locked

Recommend

In-depth understanding of uid and gid in docker containers

By default, processes in the container run with r...

Detailed explanation of MySQL batch SQL insert performance optimization

For some systems with large amounts of data, the ...

Two examples of using icons in Vue3

Table of contents 1. Use SVG 2. Use fontAwesome 3...

Implementation of MySQL GRANT user authorization

Authorization is to grant certain permissions to ...

How to use docker+devpi to build local pypi source

Some time ago, I needed to use pip downloads freq...

Defining the minimum height of the inline element span

The span tag is often used when making HTML web p...

Vue integrates PDF.js to implement PDF preview and add watermark steps

Table of contents Achieve results Available plugi...

How to correctly create MySQL indexes

Indexing is similar to building bibliographic ind...

How to optimize images to improve website performance

Table of contents Overview What is Image Compress...

Detailed explanation of how to create MySql scheduled tasks in navicat

Detailed explanation of creating MySql scheduled ...

js to create a carousel effect

I think the carousel is a relatively important po...

How to specify parameter variables externally in docker

This article mainly introduces how to specify par...