Support of Apache Solr for Spring Data

CAST supports Apache Solr for Spring Data via its com.castsoftware.nosqljava extension, since release 1.9. Details about the support provided for Java with Spring Data source code are discussed below.

Supported Libraries

Library Version Supported
Spring Data Apache Solr Up to: 4.3.x ✔️

Supported Operations

Operation Scenario Methods Supported
Insert Repository APIs org.springframework.data.repository.CrudRepository.save
org.springframework.data.repository.CrudRepository.saveAll
Solr Template APIs org.springframework.data.solr.core.SolrTemplate.saveBean
org.springframework.data.solr.core.SolrTemplate.saveBeans
org.springframework.data.solr.core.SolrTemplate.saveDocument
org.springframework.data.solr.core.SolrTemplate.saveDocuments
Select Repository APIs org.springframework.data.repository.CrudRepository.findAll
org.springframework.data.repository.CrudRepository.count
org.springframework.data.repository.CrudRepository.findById org.springframework.data.repository.CrudRepository.findAllById
org.springframework.data.repository.CrudRepository.existsById
org.springframework.data.repository.PagingAndSortingRepository.findAll
Solr Template APIs org.springframework.data.solr.core.SolrTemplate.query
org.springframework.data.solr.core.SolrTemplate.queryForCursor
org.springframework.data.solr.core.SolrTemplate.queryForFacetAndHighlightPage
org.springframework.data.solr.core.SolrTemplate.queryForFacetPage
org.springframework.data.solr.core.SolrTemplate.queryForGroupPage
org.springframework.data.solr.core.SolrTemplate.queryForHighlightPage
org.springframework.data.solr.core.SolrTemplate.queryForObject
org.springframework.data.solr.core.SolrTemplate.queryForPage
org.springframework.data.solr.core.SolrTemplate.doQueryForPage
org.springframework.data.solr.core.SolrTemplate.querySolr
org.springframework.data.solr.core.SolrTemplate.getById
Delete Repository APIs org.springframework.data.repository.CrudRepository.deleteAll
org.springframework.data.repository.CrudRepository.deleteById
org.springframework.data.repository.CrudRepository.delete
Solr Template APIs org.springframework.data.solr.core.SolrTemplate.delete
org.springframework.data.solr.core.SolrTemplate.deleteByIds
org.springframework.data.solr.core.SolrTemplate.saveDocument
org.springframework.data.solr.core.SolrTemplate.saveDocuments

Objects

Icon Description
Java ApacheSolr Client
Java ApacheSolr Index
Java Unknown ApacheSolr Index
Link type Source and destination of link Methods supported
parentLink Between Apache Solr Index Object (Collection → Client ) -
useSelectLink Between the caller Spring Data Java Method objects and Apache Solr Index findAll
findById
findAllById
findAll
count
existsById
useDeleteLink Between the caller Spring Data Java Method objects and Apache Solr Index deleteAll
deleteById
delete
useInsertLink Between the caller Spring Data Java Method objects and Apache Solr Index save
saveAll

What results can you expect?

Some example scenarios are shown below:

ApacheSolr Client

@SolrDocument(collection="Order")
public class Order {
    
    @Id
    @Indexed(name = "oid", type = "long")
    private Long orderid;
 
    @Indexed(name = "oname", type = "string")
    private String orderName;
    
    @Indexed(name = "odesc", type = "string")
    private String orderDescription;
    
    @Indexed(name = "pname", type = "string")
    private String productName;

    @Indexed(name = "cname", type = "string")
    private String customerName;
    
    @Indexed(name = "cmobile", type = "string")
    private String customerMobile;

	public Long getOrderid() {
		return orderid;
	}

	public void setOrderid(Long orderid) {
		this.orderid = orderid;
	}

	public String getOrderName() {
		return orderName;
	}

	public void setOrderName(String orderName) {
		this.orderName = orderName;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getCustomerMobile() {
		return customerMobile;
	}

	public void setCustomerMobile(String customerMobile) {
		this.customerMobile = customerMobile;
	}

	public String getOrderDescription() {
		return orderDescription;
	}

	public void setOrderDescription(String orderDescription) {
		this.orderDescription = orderDescription;
	}
    
}

Insert Operation

Insert Operation

	@PutMapping("/order")
	public String updateOrder(@RequestBody Order order){
		String description = "Order Updated";
		solrOrderRepository.save(order);
		return description;
	}

Select Operation

Select Operation

	@GetMapping("/getALL")
	public Iterable<Order> getOrder() {
		return solrOrderRepository.findAll();
	}

    public ScoredPage<Book> searchDocuments(String searchTerm) {
        Query query = new SimpleQuery(searchTerm);
        return solrTemplate.query("Book", query, Book.class);
    }

    @Query("odesc:*?0* OR oname:*?0* OR pname:*?0*")
    Page<Order> findByCustomerQuery(String searchTerm, Pageable pageable);

Delete Operation

Delete Operation

	@DeleteMapping("/order/{orderid}")
	public String deleteOrder(@PathVariable Long orderid){
		String description = "Order Deleted";
		solrOrderRepository.delete(solrOrderRepository.findByOrderid(orderid));
		return description;
	}

Known Limitations

  • If the Index/core name is not resolved in the CRUD API, then a link is created with an unknown index object.