So, I have a java based web project that displays information retrieved from 3 separate services, hosted on different servers, I use Apache Http Client to retrieve information via REST API in JSON, using Gson library. I convert the Json into POJO's that I use to display information.
Now I want to implement search feature in my project, so I installed Solr on a separate server, what I want is:
Index the JSON in solr server for all 3 services.
fetch search result from Solr in form of POJO's described in my project
I know that point (1) can be done by jsonRequestHandler
, but I don't want to write separate logic to index, I am using Solrj in my project to extract information.
So I want to know
- can solrj use my POJO definition to parse the search results?
- also any possible workflow for above working scenario, and tools required (I am new to solrj)?
Mapping a POJO for Solr
To do so you need to annotate the fields/access-methods of your POJO with the
org.apache.solr.client.solrj.beans.Field
-Annotation.Of course those fields need to match the fields of your schema.xml either by their name directly or by the name you point Solr to by giving the name in the Field annotation.
As example you have the following definition of
fields
in your schema.xmlThen you would have a POJO like this
Using a POJO to update Solr's Index
The code to index those POJOs is rather straight forward. You can use solrj's SolrServer for that purpose.
Further reading
The results are a write up of our code and the following references
Yes that is possible, I was doing some similar thing once. But I think you should write some converter, which would fetch the results from
SolrDocumentList
and from eachSolrDocument
put the result to your POJO's.Read about setting the query parameters and getting the results with
solrj
, and I think it wouldn't be a problem for you to do this. The converter itself should be easy to write, because you can access every field indexed from the result. Also pay attention to narrowing the results itself.These are some guides, as I don't feel experienced with solr searching. I don't know if it will help you much, but I hope so.