solr8.0.0 basic installation and substantially in the springboot (win10)

1. Download solr

  Download: http://archive.apache.org/dist/lucene/solr/

  The address can also download the previous version, I downloaded solr-8.0.0.zip version here. After the download is complete on the D: \ directory under the project, and then extract to the current directory.

2, startup, shutdown solr

  Navigate to the bin folder solr directory after decompression, after which go right into the Powershell enter the following command:

Start. \ Solr start 
to close. \ Solr STOP -all

3. Create core

  In solr directory \ server \ solr core folder, create a folder on my side folder name is called xjxcc. Then \ server \ solr \ configsets \ sample_techproducts_configs following conf folder to the core file you just created folder below.

  Solr start after completion of the above operation, after a successful start to open the browser to access http://127.0.0.1:8983/solr/#/ address, you can see solr management interface. Click on the left of the Core Admin, the new page name and instanceDir input box were changed to core file you just created folder name (I am here is xjxcc), then click on Add Core button below to successfully create core (originally cut a Figure Zhang operation, the result CSDN upload Bild unknown error).

  After creating a successful, will generate a file folder and a core file you just created folder below, this means that create success.

4, create springboot project and test code

  How to create a project springboot not say, paste the following key documents:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xjxcc</groupId>
    <artifactId>solrTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>solrTest</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
        <relativePath />
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-solr</artifactId>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.6.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
Server: 
  context-path: / 
  Port: 9633 
the Spring: 
  the Data: 
    Solr: 
      behind # This xjxcc is the name of core folder, where you can also do not write this, if this is not specified core, so when used in your code, you need to Specifies the core. 
      # Code in place to specify core of the Notes may see 
      host: http://127.0.0.1:8983/solr/xjxcc
@EnableSwagger2
@RestController
@RequestMapping("/")
public class SolrController {

    @Autowired
    private SolrClient client;

    @PostMapping("/insert")
    public String insert(String content) throws IOException, SolrServerException {
        try {
            String idStr = String.valueOf(System.currentTimeMillis());
            SolrInputDocument doc = new SolrInputDocument();
            doc.setField("id", idStr);
            doc.setField("name" , Content); 

            client.add (DOC); // If the configuration file does not specify the core, the first argument of this method would need to specify the name of the core, such as client.add ( "xjxcc", DOC); 
            Client .commit (); // if the core is not specified in the configuration file, the first parameter of this method it is necessary to specify the name of core client.commit ( "xjxcc"); 
            return idStr; 
        } the catch (Exception E) { 
            e.printStackTrace ( ); 
        } 
        return "error" ; 
    } 
}

  Then after the start of the project, to enter http: // localhost: 9633 / swagger -ui.html address to test insertion index operations. After successful insertion, in the lower left solr management interface has a drop-down box, select the core you created after, and then select Query, and finally dragged down, click Execute Query to see you just insert the index.

 

other problems:

  We have just embed the two columns (id, name), if you want to add a column, such as name, called zhangsan, and then start the project, inserted in the index, you can not see in solr management platform in the column names and corresponding value, because the id, name two columns already in the default configuration in solr. This situation resolved as follows:

  In the core files you create the following folder, open the conf folder, modify the inside of the managed-schema file, modify the following locations:

132行后面增加(后面这几行随意位置增加就可以)
<field name="zhangsan" type="text_general" indexed="true" stored="true"/>

245行后面增加(后面这几行随意位置增加就可以)
<copyField source="zhangsan" dest="text"/>

  Solr restart after changes are complete, and then reinsert the index can be successfully operated.

Guess you like

Origin www.cnblogs.com/kawhileonardfans/p/10966903.html