Spring boot integration solr8 (1)


Environmental Science:ubuntu18 + springboot2.0 + solr-8.0.0

Part I installing Solr

First go to the official website to download Solr: index of / Apache / Lucene / Solr / 8.0.0
I download the zip package here. After downloading, unzip command unzip the following files:
Spring boot integration solr8 (1)

Enter bin directory and executesudo ./solr -startOrders
There are two possible errors:

  1. You will be prompted that Java home cannot be found. The solution is to add it in SolrExport java_home = 'your JDK path'Yes.
  2. Root startup needs to be added-force parameter, the error message is as follows:

Spring boot integration solr8 (1)

Well, run it againsudo ./solr start -force, run successfully.
Spring boot integration solr8 (1)

The default port for Solr is8983, open browser inputlocalhost:8983, you can see that Solr has access~
Spring boot integration solr8 (1)

The second part creates the core and imports MySQL data

Select left sideCoreAdminChoose againAdd Core, enter the name of the core and the path of the instance, and the next three defaults are good.

Spring boot integration solr8 (1)

Click Add core to submit the information. Here I encounter an error message, as follows:

Spring boot integration solr8 (1)

The corresponding configuration file cannot be found in the core directory. Solution: copy the conf folder below to the newly created core directory/usr/local/solr-8.0.0/server/solr/new_core2

Spring boot integration solr8 (1)

Click Add core again to create successfully~

Spring boot integration solr8 (1)

Next, import the data in MySQL. We will use the DIH (data import handler) provided by Solr to import the data.
Three jar packages need to be imported in this step(solr-dataimporthandler-8.0.0.jarolr-dataimporthandler-extras-8.0.0.jarandmysql-connector-java-8.0.15.jar), edit three files(db-data-confg.xmlsolrconfig.xmlas well asmanaged-schema)。

Import jar package

Enter into/usr/local/solr-8.0.0/distDirectory, willsolr-dataimporthandler-8.0.0.jarandsolr-dataimporthandler-extras-8.0.0.jarCopy to/usr/local/solr-8.0.0/server/solr-webapp/webapp/WEB-INF/lib, and then go to the MVN warehouse to download a MySQL connector java package, which is also copied here.

Edit profile

  • First we need to enter/usr/local/solr-8.0.0/example/example-DIH/solr/db/confCatalog, copydb-data-config.xmlGo to the conf folder we just copied/usr/local/solr-8.0.0/server/solr/new_core2/conf, you can change a file name at will, or you can use its default, as follows, I changed it tomysql-db.xml:

Spring boot integration solr8 (1)

Edit the filevim mysql-db.xml, modify the original content to our own needs:
Modify datesource:

<dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://" user="root" password="" />

Join entity:
Spring boot integration solr8 (1)

  • Then exit and edit another filesolrconfig.xml, add the following information:
  <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">mysql-db.xml</str>

mysql-db.xmlIt was just copieddb-data-config.xmlThe file name of.

  • Save exit, editmanaged-schemaJoin in
<!-- custom fields-->
<field name="title" type="string" indexed="true" stored="true"/>
<field name="content" type="string" indexed="true" stored="true"/> 
<field name="labels" type="string" indexed="true" stored="true"/> 

Save – > Exit – > Restart Solr,sudo ./solr restart -force

Open againlocalhost:8983Management page, select the newly created core — > selectDateImport> selectionfull-importClick refresh to refresh the import

Spring boot integration solr8 (1)

At this point, the data import is finished!

In the following articles, we will add Chinese word segmentation and how to use Solr in the spring boot project