1

I have added XSLT file to format my results in Apache solr.

By navigating to the following URL, the results are coming as expected, after the XSLT transformation:

http://localhost:8983/solr/en_US/select?callback=jsonCallback&sort=articleDate%20desc&q=*:*&wt=xslt&tr=ra.xsl

I need to achieve the same thing using Solrj API. I am not able to transform the result using Solrj API in Java.

SolrServer solrServer = new HttpSolrServer("http://localhost:8983/solr/en_US");
NamedList<Object> params = new NamedList<Object>();
params.add("wt", "xslt");
params.add("tr", "ra.xsl");

SolrQuery query = new SolrQuery();
query.add(ModifiableSolrParams.toSolrParams(params));
query.setQuery("*:*");
query.addSort("articleDate",SolrQuery.ORDER.desc);

QueryResponse response = solrServer.query(query);
SolrDocumentList results = response.getResults();

I am setting the parameters as above. Please help me to achieve getting the same response using Solrj API.

Martín Schonaker
  • 7,022
  • 4
  • 28
  • 55
  • See [this](https://mail-archives.apache.org/mod_mbox/lucene-solr-user/201403.mbox/%3C53285205.3030002@elyograg.org%3E). You might have to fire your entire query in the `setQuery()` method in order to have solr honor your response type. – Binoy Dalal Feb 24 '16 at 09:14

1 Answers1

0

I do not think that you could get XSTL using solrj. You can have a look on this site. https://wiki.apache.org/solr/javabin#Supported_Types. Javabin is the default format used by SolrJ.

What you can do is just make a simple http request at the url http://localhost:8983/solr/en_US/select?callback=jsonCallback&sort=articleDate%20desc&q=:&wt=xslt&tr=ra.xsl

Look on this site on how to make a http request using java How to send HTTP request in java? and get the response (xstl) from there.

Hope this helps

Community
  • 1
  • 1
Periklis Douvitsas
  • 2,233
  • 1
  • 10
  • 14