Code Monkey home page Code Monkey logo

spring-data-solr's Introduction

Spring Data Solr

The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services.

The Spring Data Solr project provides integration with the Apache Solr search engine.

Getting Help

Help is currently under construction but on its way.

If you are new to Spring as well as to Spring Data, look for information about Spring projects.

Quick Start

SolrTemplate

SolrTemplate is the central support class for solr operations.

SolrRepository

A default implementation of SolrRepository, aligning to the generic Repository Interfaces, is provided. Spring can do the Repository implementation for you depending on method names in the interface definition.

The SolrCrudRepository extends PagingAndSortingRepository

    public interface SolrCrudRepository<T, ID extends Serializable> extends SolrRepository<T, ID>, PagingAndSortingRepository<T, ID> {
    } 

The SimpleSolrRepository implementation uses SolrJ converters for entity transformation and therefore requires fields to be annotated with org.apache.solr.client.solrj.beans.Field.

    public interface SolrProductRepository extends SolrCrudRepository<Product, String> {

        //Derived Query will be "q=popularity:<popularity>&start=<page.number>&rows=<page.size>"
        Page<Product> findByPopularity(Integer popularity, Pageable page);

        //Will execute count prior to determine total number of elements
        //Derived Query will be "q=name:<name>*&start=0&rows=<result of count query for q=name:<name>>"
        List<Product> findByNameStartingWith(String name);

        //Derived Query will be "q=inStock:true&start=<page.number>&rows=<page.size>"
        Page<Product> findByAvailableTrue(Pageable page);
  
        @Query("inStock:false")
        Page<Product> findByAvailableFalseUsingAnnotatedQuery(Pageable page);
        
        //Will execute count prior to determine total number of elements
        //Derived Query will be q=inStock:false&start=0&rows=<result of count query for q=inStock:false>&sort=name desc
        List<ProductBean> findByAvailableFalseOrderByNameDesc();
    }

SolrRepositoryFactory will create the implementation for you.

    public class SolrProductSearchRepositoryFactory {

        @Autwired
        private SolrOperations solrOperations;
  
        public SolrProductRepository create() {
  	        return new SolrRepositoryFactory(this.solrOperations).getRepository(SolrProductRepository.class);
        }
  
    }

Furthermore you may provide a custom implementation for some operations.

    public interface CustomSolrRepository {

        Page<Product> findProductsByCustomImplementation(String value, Pageable page);
	
    }

    public class CustomSolrRepositoryImpl implements CustomSolrRepository {
	
        private SolrOperations solrTemplate;
	
        public CustomSolrRepositoryImpl(SolrOperations solrTemplate) {
            super();
            this.solrTemplate = solrTemplate;
        }

        @Override
        public Page<Product> findProductsByCustomImplementation(String value, Pageable page) {
            Query query = new SimpleQuery(new SimpleStringCriteria("name:"+value)).setPageRequest(page);
            return solrTemplate.executeListQuery(query, Product.class);
        }

    }
    
    public interface SolrProductRepository extends CustomSolrRepository, SolrCrudRepository<Product, String> {
    	
    	Page<Product> findByPopularity(Integer popularity, Pageable page);
    	
    }
    
    public class CustomSolrProductSearchRepositoryFactory {

        @Autwired
        private SolrOperations solrOperations;
  
        public SolrProductRepository create() {
  	        return new SolrRepositoryFactory(this.solrOperations)
  	            .getRepository(SolrProductRepository.class, new CustomSolrRepositoryImpl(this.solrOperations));
        }
  
    }

Contributing to Spring Data

Please refer to CONTRIBUTING

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.