One of the great features of Solr is the ability to return search results in different formats. Json, XML, PHP and others are supported. Here is a screenshot of Solr’s Response Writer options in the Solr Administration Panel.
We’re going to do something not in the list, but cooler. We’re going to load Solr search results directly into a Java Data Object List. Below is the entirety of the Java code we’re using to perform a Solr Query and convert the response into a Data Object List.
The Code of Power in the above excerpt is
List<NixMashupDoc> nixMashupDocs = response.getBeans(NixMashupDoc.class);
The NixMashupDoc Java Object we’re loading the Solr Documents into shown below is as ordinary as ordinary gets, but here is a tip on object property types. If you recall from the post on Using SolrJ with Java Objects we used a NixMashupLink object to enter data. We’re using a separate NixMashupDoc object here.
To explain the reason for a two objects notice the linkId and mashupId properties below set as Strings. Also notice the linkDatetime is a Date. In the NixMashupLink object used when entering data into Solr these properties were Integers and Timestamps as you’d expect. We’re changing the field properties to match their representation in the Solr Index, in other words.
For completeness, here’s the output of the search in Eclipse Console.