# spring-data-solr **Repository Path**: mirrors_krm1312/spring-data-solr ## Basic Information - **Project Name**: spring-data-solr - **Description**: Spring Data - Solr integration - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-25 - **Last Updated**: 2025-12-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Spring Data Solr ====================== The primary goal of the [Spring Data](http://www.springsource.org/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](http://lucene.apache.org/solr/) search engine Providing its own extensible ```MappingSolrConverter``` as alternative to ```DocumentObjectBinder``` Spring Data Solr handles inheritance as well as usage of custom Types such as ```GeoLocation``` or ```DateTime```. Getting Help ------------ * [Reference Documentation](http://docs.spring.io/spring-data/data-solr/docs/current-SNAPSHOT/reference/html/) * [API Documentation](http://docs.spring.io/spring-data/data-solr/docs/current-SNAPSHOT/api/) * [Spring Data Project](http://www.springsource.org/spring-data) * [Issues](https://jira.springsource.org/browse/DATASOLR) * [Code Analysis](https://sonar.springsource.org/dashboard/index/org.springframework.data:spring-data-solr) If you are new to Spring as well as to Spring Data, look for information about [Spring projects](http://www.springsource.org/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``` ```java public interface SolrCrudRepository extends SolrRepository, PagingAndSortingRepository { } ``` The ```SimpleSolrRepository``` implementation uses ```MappingSolrConverter```. In order support native solrj mapping via ```DocumentObjectBinder``` fields have to be annotated with ```org.apache.solr.client.solrj.beans.Field``` or ```org.springframework.data.solr.core.mapping.Indexed```. To enable native solrj mapping use ```SolrJConverter``` along with ```SolrTemplate```. ```java public interface SolrProductRepository extends SolrCrudRepository { //Derived Query will be "q=popularity:&start=&rows=" Page findByPopularity(Integer popularity, Pageable page); //Will execute count prior to determine total number of elements //Derived Query will be "q=name:*&start=0&rows=>" List findByNameStartingWith(String name); //Derived Query will be "q=inStock:true&start=&rows=" Page findByAvailableTrue(Pageable page); //Derived Query will be "q=inStock:&start=&rows=" @Query("inStock:?0") Page findByAvailableUsingAnnotatedQuery(boolean inStock, Pageable page); //Will execute count prior to determine total number of elements //Derived Query will be "q=inStock:false&start=0&rows=&sort=name desc" List findByAvailableFalseOrderByNameDesc(); //Execute faceted search //Query will be "q=name:&facet=true&facet.field=cat&facet.limit=20&start=&rows=" @Query(value = "name:?0") @Facet(fields = { "cat" }, limit=20) FacetPage findByNameAndFacetOnCategory(String name, Pageable page); //Boosting criteria //Query will be "q=name:^2 OR description:&start=&rows=" Page findByNameOrDescription(@Boost(2) String name, String description, Pageable page); //Highlighting results //Query will be "q=name:()&hl=true&hl.fl=*" @Highlight HighlightPage findByNameIn(Collection name, Page page); //Spatial Search //Query will be "q=location:[, TO ,]" Page findByLocationNear(BoundingBox bbox); //Spatial Search //Query will be "q={!geofilt pt=, sfield=location d=}" Page findByLocationWithin(GeoLocation location, Distance distance); } ``` ```SolrRepositoryFactory``` will create the implementation for you. ```java 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. ```java public interface SolrProductRepository extends SolrCrudRepository, SolrProductRepositoryCustom { @Query(fields = { "id", "name", "popularity" }) Page findByPopularity(Integer popularity, Pageable page); List findByAuthorLike(String author); } public interface SolrProductRepositoryCustom { Page findProductsByCustomImplementation(String value, Pageable page) } public class SolrProductRepositoryImpl implements SolrProductRepositoryCustom { private SolrOperations solrTemplate; @Override public Page findProductsByCustomImplementation(String value, Pageable page) { Query query = new SimpleQuery(new SimpleStringCriteria("name:"+value)).setPageRequest(page); return solrTemplate.queryForPage(query, Product.class); } @Autowired public void setOperations(SolrOperations operations) { this.operations = operations; } } ``` Go on and use it as shown below: ```java @Service public class ProductService { private SolrProductRepository repository; public void doSomething() { repository.deleteAll(); Product product = new Product("spring-data-solr"); product.setAuthor("Christoph Strobl"); product.setCategory("search"); repository.save(product); Product singleProduct = repository.findById("spring-data-solr"); List productList = repository.findByAuthorLike("Chr"); } @Autowired public void setRepository(SolrProductRepository repository) { this.repository = repository; } } ``` ### XML Namespace You can set up repository scanning via xml configuration, which will happily create your repositories. ```xml ``` Maven ----- ### RELEASE ```xml org.springframework.data spring-data-solr 1.0.0.RELEASE ``` ### Build Snapshot ```xml org.springframework.data spring-data-solr 1.1.0.BUILD-SNAPSHOT spring-maven-snapshot http://repo.springsource.org/libs-snapshot ``` Contributing to Spring Data --------------------------- Please refer to [CONTRIBUTING](https://github.com/SpringSource/spring-data-solr/blob/master/CONTRIBUTING.md)