Sorl environment setup and mysql table import data

windows installation solr

1. Solr windows installation process

Official website download address: https://solr.apache.org/downloads.html

I downloaded version 8.11.2. Note that if you need to download the latest version, the jdk version must be relatively high, otherwise the startup will not be compatible.

Insert image description hereAfter downloading, unzip it to your own folder location

Start solr: Start the command window as an administrator.
Enter the software bin directory: \file\solr-8.11.2\bin
Common commands:

//solr服务默认端口为8983
solr start
//可以指定端口
solr start -p 8984

//关闭solr服务的所有端口
solr stop -all
//关闭solr服务的指定端口
solr stop -p 8984

After successful startup, access the address: http://localhost:8983/
Insert image description here
2. Import mysql data into solr
cmd command to create an instance:

solr create -c "zyy-test"
说明:zyy-test 可以是你自己创建的实例名称

After creation, you can see the instance you created on the UI interface. You can also create and view individuals on the UI without using commands.

Modify the configuration:
1. Import the jar package.
  Database-driven jar: mysql-connector-java-8.0.11.jar (note that the version of the jar package here depends on the version of your database. My database is mysql8.0)

data-import jar: There are these two packages solr-dataimporthandler-8.11.2.jar and solr-dataimporthandler-extras-8.11.2.jar in the root directory dist.
  Copy these three jar packages to \solr-8.11.2\server\solr-webapp\webapp\WEB-INF\lib
2. Modify the configuration and directory: \solr-8.11.2\server\solr\zyy_test\conf
The instance created in the previous step can be seen in the solr file.
Insert image description here
We enter the directory \solr-8.11.2\server\solr\zyy_test\conf
data-config.xml configuration file configuration. If there is no file, add the file to add the data source and mapping table.

<dataConfig>
    <dataSource
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://127.0.0.1:3306/txxy?characterEncoding=utf-8"
            user="zyy"
            password="#alitest_wz92" />
    <document>
        <entity name="phone_area" query="select * from phone_area">
            <field column="cname" name="cname" />
        </entity>
        <entity name="tb_xzqh_areas" query="select * from tb_xzqh_areas">
            <field column="id" name="id" />
            <field column="code" name="code" />
            <field column="name" name="name" />
            <field column="cityCode" name="cityCode" />
            <field column="provinceCode" name="provinceCode" />
            <field column="modify_time" name="modify_time" />
        </entity>
    </document>
</dataConfig>

Modifying the solrconfig.xml file requires introducing a data source

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

Modify the managed-schema file. Some versions are called schema. I am confused here. Add
the corresponding word segmentation field to the table, otherwise it cannot be displayed.

    <field name="cname" type="string" indexed="true" stored="true" multiValued="false"/>

    <field name="code" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="name" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="cityCode" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="provinceCode" type="string" indexed="true" stored="true" multiValued="false"/>

Insert image description here
Correspondence table:

CREATE TABLE `tb_xzqh_areas` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(6) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `cityCode` varchar(6) DEFAULT NULL,
  `provinceCode` varchar(6) DEFAULT NULL,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `modify_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `udx_areas_code` (`code`)
) ENGINE=InnoDB AUTO_INCREMENT=10886 DEFAULT CHARSET=utf8 COMMENT='县级(区县)';

CREATE TABLE `phone_area` (
  `rcode` varchar(6) CHARACTER SET utf8 DEFAULT NULL,
  `ccode` varchar(6) CHARACTER SET utf8 DEFAULT NULL,
  `acode` varchar(6) CHARACTER SET utf8 DEFAULT NULL,
  `rname` varchar(100) CHARACTER SET utf8 DEFAULT NULL,
  `cname` varchar(100) CHARACTER SET utf8 DEFAULT NULL,
  `aname` varchar(100) CHARACTER SET utf8 DEFAULT NULL,
  `nname` varchar(200) CHARACTER SET utf8 DEFAULT NULL,
  KEY `idx_ccode` (`ccode`),
  KEY `idex_acode` (`acode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

After configuration is complete, restart sorl

Import data:
Insert image description here
Query the imported data in full:
Insert image description here
This completes the data import

3. Delete the imported data.
In the Solr client, access your index library (I think the most convenient method)

1)Documents type select XML
2)Documents enter the following statement

<delete><query>*:*</query></delete>
<commit/>

Insert image description here
Click Submit Document.
2. Solr-use url and use stream related parameters to delete data:

like:

Delete data based on id

http://localhost:8080/solr/update/?stream.body=

id值&stream.contentType=text/xml;charset=utf-8&commit=true

Delete data based on query parameter conditions

http://localhost:8080/solr/update/?stream.body= 参数&stream.contentType=text/xml;charset=utf-8&commit=true

stream related parameters:

stream.file=(server local file);

stream.url respectively points to your deleted text, here is the direct string content using the stream.body parameter.

The commit parameter refers to submission. Only after submission can you see the deletion effect.

There are two types of deletion instructions, one is: using packaging; the other is: packaging. The instructions are very obvious, one is the id value (the value of the field pointed to by the uniqueKey in schema.xml, not the docId inside the index); the query value is the query string, such as: title: "solr lucene".

Finally, I wish you good luck~~

Guess you like

Origin blog.csdn.net/weixin_43829047/article/details/126303826