Environment: Ubuntu 18 + Spring Boot2.0 + Solr-8.0.0

The first part installs Solr

Go to the official website to download Solr:The Index of/apache lucene/solr / 8.0.0

I downloaded the zip package here. After downloading, unzip command unzip to get the following files:

Go to the bin directory and execute the sudo./ solr-start command. There are two possible errors you may encounter:

  1. It will tell you that JAVA_HOME cannot be found. The solution is to add it to SolrExport JAVA_HOME=' Your JDK path 'Can;
  2. Root boot needs to be added- the force parameters, the error message is as follows:

Okay, run it againsudo ./solr start -force, successfully run.

The default port for Solr is8983, open a browser and typelocalhost:8983, you can see that Solr is now accessible ~

The second part creates the core and imports the MySQL data

Select CoreAdmin on the left, then Add Core, and enter the name of the Core and the instance path. The following three defaults are fine.

Click Add Core to submit information. Here I encountered an error message as follows:

/usr/local/solr-8.0.0/server/solr/new_core2: /usr/local/solr-8.0.0/server/solr/new_core2: /usr/local/solr-8.0.0/server/solr/new_core2

Click Add Core again, and the creation is successful

Next, import the data from MySQL. We will use Solr’s built-in DIH(DataIpHandler) to import the data. This step requires importing three jars (solr-dataImporthHandler -8.0.0.jar, olr-dataImporthHandler -extras-8.0.0.jar, and mysql-connector-java-8.0.15.jar). Edit three files (db-data-confg.xml, solrconfig.xml, and managed-schema).

Import the jar package

/usr/local/solr-8.0.0/dist Copy solr-dataImporthHandler -8.0.0.jar and solr-dataImporthHandler -extras-8.0.0.jar to /usr/local/solr-8.0.0/server/solr-webapp/web App/web-inf /lib, then go to the MVN repository and download a mysql-connector-java package, copy it here as well.

Edit configuration files

  • The first thing we need to do is go into/ usr/local/solr - 8.0.0 / example/example - DIH/solr/db/confDirectory, 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 filename arbitrarily, or you can use its default, as follows, I changed it tomysql-db.xml:

Edit the file Vim mysql-db.xml to change the original contents to our own requirements:

< the dataSource driver = ". Com. Mysql. JDBC driver "url =" JDBC: mysql: / / / dbname "user" root ", "= =" "/ >

To join the entity:

  • 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.xml = mysql-db.xml = mysql-db.xml = mysql-db.xml

  • Save exit, editmanaged-schemaTo join
<! -- 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"/>

Solr, sudo./ Solr Restart-Force. Solr, sudo

Open the localhost:8983 administration page again, select the newly created core –>, select DateImport –>, select Full-Import –> submit –>, click Refresh to Refresh, you can see the successful import:

At this point, the data import is complete!

In future articles we will include Chinese participle and how to use Solr in a SpringBoot project