I. Project structure

Add SpringBoot, Solr, Freemarker dependencies to the pom. XML file

<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <dependency> <groupId>cn.hutool</groupId> < artifactId > hutool -all < / artifactId > < version > 5.2.0 < / version > < / dependency > <! Spring framework.boot</ grouppid > --> <dependency> < grouppid >org.springframework.boot</ grouppid > --> <dependency> < grouppid >org.springframework.boot</ grouppid > <artifactId>spring-boot-starter-web</artifactId> </dependency> <! Spring Boot project introduces solr dependencies --> <! Solrj </artifactId> solrj</artifactId> </dependency>. Solrj </artifactId> solrj</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-solr</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> The < version > 1.16.14 < / version > < scope > provided < / scope > < / dependency > < / dependencies >

3. Make.ftl template

1. Create Excel template and fill in some fake data to facilitate subsequent positioning

2, Save as XML format

3. Modify the suffix to FTL

4. Processing FTL files

Make sure you delete ss:ExpandedRowCount=”5″, as you would have exceeded the “ExpandedRowCount” limit later on

Put stat. FTL into resources/templates

4. Using Solr for multi-field grouping statistics on SpringBoot

It is important to note that the default DEFAULT_PATH is “/select” and that there is no place to change the path, so if the solr service has a custom /select option, it can copy the source code. Then create a new HttpSolrClient locally of the same name, as you can see from my project structure

Expanding knowledge: What are the differences between q and fq parameters in Solr?

If you use Q =content:” China “, you will find all content containing “China “, and then order by score, which will be sorted according to the similarity of content.

If fq is used,q is set to:. So Solr will order by score first, and since the condition is :, all documents will have the same correlation, so even if FQ is used to filter, it will return the first one in the list but not the one with the highest correlation.

To sum up, if score is the priority ranking condition, then the condition must be placed in the parameter q, while Fq is just the filtering of the condition without weighted correlation as the priority ranking.

5. Encapsulate the data, render it to the FTL template, and export Excel



You may need to go to Application.yml to configure the load path of the Freemarker template. There are a number of default configurations, but these two lines will suffice for the general needs. If you have special configuration requirements, you can visit the official website

Source address: https://github.com/AsLightJav…

If you don’t know or encounter problems, you can contact me by leaving a message below.