yml
spring:
data:
solr:
host: http://localhost::8983/solr
pom.xml
<!--solr 这里注意springboot 版本-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
springboot 版本是1.5.9 开启solr自动配置 ,之前1.5.2 集成发送solr的http请求core重复
SolrDocument 注解指定solr core
/**
* @author lcc
*/
@SolrDocument(solrCoreName = "kcore_onekey")
@data
public class Product {
@Id
@Field
private String id;
@Field(value = "CAPTURE_TIME")
private long captureTime;
@Field(value = "DETAILS")
private String details;
@Field(value = "CONTENT")
private String content;
@Field(value = "INFO_TYP")
private int infoTyp;
@Field(value = "_version_")
private long version;
}
spring-date -jpa方式操作方便简介 可参考([https://projects.spring.io/spring-data-solr]
/**
* @author lcc
*/
public interface ProductRepository extends SolrCrudRepository<Product, String> {
//fragsize 默认返回的高亮字段是有长度限制fragsize 可设置长度
// @Highlight(prefix = "<font color='red'>", postfix = "</font>",fragsize = 10000)
// HighlightPage<Product> findByContentMatches(String content, Pageable pageable);
Page<Product> findByContentMatches(String content, Pageable pageable);
}