You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Federico Valeri <fe...@gmail.com> on 2012/07/27 17:32:55 UTC

Problem with Solr 4.0-ALPHA and JSON response

Hi all, I'm new to Solr, I have a problem with JSON format, this is my Java
client code:

PrintWriter out = res.getWriter();
res.setContentType("text/plain");
String query = req.getParameter("query");
SolrServer solr = new HttpSolrServer(solrServer);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/select");
params.set("q", "contenuto:(" + query + ")");
params.set("hl", "true");
params.set("hl.fl", "id,contenuto,score");
params.set("wt", "json");

QueryResponse response = solr.query(params);
log.debug(response.toString());
out.print(response.toString());
out.flush();

Now the problem is that I recieve the response but it doesn't trigger the
javascript callback function.
I see "wt=javabin" in SolrCore.execute log, even if I set wt=json in
paramters, is this normal?
This is the jQuery call to the server:

$.getJSON('solrServer.html', {query:
escape($('input[name=query]:visible').val())}, function(data){
    var view = '';
    for (var i=0; i<data.response.docs.length; i++) {
        view += '<p>'+data.response.docs[i].contenuto+'</p>';
    }
    $('#placeholder').html(view);
});

Thanks for reading.

Re: Problem with Solr 4.0-ALPHA and JSON response

Posted by Sami Siren <ss...@gmail.com>.
On Fri, Jul 27, 2012 at 6:32 PM, Federico Valeri <fe...@gmail.com> wrote:
> Hi all,

Hi,

> I'm new to Solr, I have a problem with JSON format, this is my Java
> client code:
>

The java client (SolrServer) can only operate with xml or javabin
format. If you need to get the json response from Solr by using java
you could just use a http client directly and bypass the solr client.

> Now the problem is that I recieve the response but it doesn't trigger the
> javascript callback function.
> I see "wt=javabin" in SolrCore.execute log, even if I set wt=json in
> paramters, is this normal?

yes, to control the format used by the client there's a method
HttpSolrServer#setParser that set's the client parser (that also
overrides the wt param when the request is made)

--
 Sami Siren