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

LibraryVersionSupported
Spring Data Apache Solrexternal linkUp to: 4.3.x✔️

Supported Operations

OperationScenarioMethods Supported
InsertRepository APIsorg.springframework.data.repository.CrudRepository.save
org.springframework.data.repository.CrudRepository.saveAll
Solr Template APIsorg.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
SelectRepository APIsorg.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 APIsorg.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
DeleteRepository APIsorg.springframework.data.repository.CrudRepository.deleteAll
org.springframework.data.repository.CrudRepository.deleteById
org.springframework.data.repository.CrudRepository.delete
Solr Template APIsorg.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

IconDescription
Java ApacheSolr Client
Java ApacheSolr Index
Java Unknown ApacheSolr Index
Link typeSource and destination of linkMethods supported
parentLinkBetween Apache Solr Index Object (Collection → Client )-
useSelectLinkBetween the caller Spring Data Java Method objects and Apache Solr IndexfindAll
findById
findAllById
findAll
count
existsById
useDeleteLinkBetween the caller Spring Data Java Method objects and Apache Solr IndexdeleteAll
deleteById
delete
useInsertLinkBetween the caller Spring Data Java Method objects and Apache Solr Indexsave
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.