Use SPRING-DATA-SOLR to do SOLR client

Source: Internet
Author: User
Tags solr

SOLR's client basically has only one, that is SOLRJ,SPRING-DATA-SOLR is done on the basis of SOLRJ encapsulation, so unified into Spring-data style

Official website:

http://projects.spring.io/spring-data-solr/

The simplest way to use spring-data is to use spring-boot, noting that multiple spring-data are not common, since we have also used SPRING-DATA-JPA as an ORM,

A new project is created here to use SPRING-DATA-SOLR as a client for the SOLR server, and then to use it in a distributed, collaborative usage.

First build Spring-boot project, refer to another blog for details.

Add Dependencies:

< Dependency >            < groupId >org.springframework.boot</groupId>            <  Artifactid>spring-boot-starter-data-solr</artifactid>         </dependency>

Because Spring-boot is a centralized configuration, the following configuration is added to the application.properties file:

  

# SOLR (solrproperties) spring.data.solr.host=http://localhost:8983/solr/mark#spring.data.solr.zkhost= Spring.data.solr.repositories.enabled=true

That would be a complete configuration.

  

Using SPRING-DATA-SOLR is almost as much as using a SPRING-DATA-JPA:

  

 Public Interface extends Solrcrudrepository<searchmark, string> {    @Query ("value:?0")    List<searchmark > findallbyvalue (String Markey, pageable pageable);}

But there are some differences:

[Email protected] is the SOLR syntax, and the parameter count is starting from 0 (SPRING-DATA-JPA is starting from 1)

2. Each mapped entity class must have a @id primary key

  

@Entity Public classSearchmarkImplementsSerializable {Private Static Final LongSerialversionuid = 1229830543809682342L; @org. Springframework.data.annotation.IdPrivateString ID;//Unique PRIMARY Key@Field ()PrivateString value;//the value of the label@Field ()Private intType//type@Field ("DATAM_ID")    Private intDatamid;//Data ID@Field ("Create_time") @JsonFormat (Pattern= "Yyyy-mm-dd HH:mm:ss", timezone = "gmt+08")    PrivateDate Createtime;//creation Time

Note that @id is @org. Springframework.data.annotation.Id

  

Other usage references:

http://projects.spring.io/spring-data-solr/

http://docs.spring.io/spring-data/solr/docs/1.0.0.RC1/reference/html/

Http://www.petrikainulainen.net/programming/solr/spring-data-solr-tutorial-crud-almost/?utm_source=tuicool &utm_medium=referral

  

Use SPRING-DATA-SOLR to do SOLR client

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.