As you may recall we’re looking at Solr in our NixMash Spring GitHub app. In our last post we configured four different Solr Repositories shown here. You can find the complete source for these repos in the v0.2.4 branch of NixMash Spring.
I decided to focus on two different Solr Repository configuration types, a Custom Solr Repository and a Simple Solr Repository.
With that as a pretext, it’s time to start using those repos! In this post we’re going to cover simple Solr CRUD operations the Spring Data way. Those operations are shown below in the @Test method and commented by operation.
We’re using our “dev” Spring Profile and our Embedded Solr Server which is populated with a known number of documents we will want to test with later. That’s why we’re Asserting against an INITIAL_RECORD_COUNT value.
It’s interesting to see how we’re using all standard Spring Data functions against the Solr database. save(product), findOne(productID) and delete(product) pretty much do the job for us. We’ll use a Solr PartialUpdate() function when looking at Custom actions in our next post, but it’s not necessary when updating a product object locally with a save(product) in Solr which updates a document by ID on save() if it already exists.
Next time, custom Solr operations where we’ll be looking at more Repository code.