You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Ahmet Arslan <io...@yahoo.com> on 2010/12/25 03:45:26 UTC

phps with SolrDocument

JSONWriter.writeSolrDocument method calls writeMapOpener(-1);
However its subclass (PHPSerilalizedWriter) throws an exception in its writeMapOpener method if size<0. This makes impossible to use SolrDocumentList as response with phps. (somehow related to solr-2291)

Here is a snippet demonstrates the case.

public class PHPSTest extends SolrTestCaseJ4 {
  @BeforeClass
  public static void beforeClass() throws Exception {
    initCore("solrconfig.xml", "schema.xml");
  }

  @Test
  public void testPHPS() throws Exception {

    SolrQueryRequest req = req(CommonParams.WT, "phps");
    SolrQueryResponse rsp = new SolrQueryResponse();
    PHPSerializedResponseWriter w = new PHPSerializedResponseWriter();

    Set<String> returnFields = new HashSet<String>(1);
    returnFields.add("id");
    returnFields.add("score");
    rsp.setReturnFields(returnFields);

    StringWriter buf = new StringWriter();

    SolrDocument solrDoc = new SolrDocument();
    solrDoc.addField("id", "1");
    solrDoc.addField("subject", "hello2");
    solrDoc.addField("title", "hello3");
    solrDoc.addField("score", "0.7");

    SolrDocumentList list = new SolrDocumentList();
    list.setNumFound(1);
    list.setStart(0);
    list.setMaxScore(0.7f);
    list.add(solrDoc);

    rsp.add("response", list);

    w.write(buf, req, rsp);
    System.out.println(buf.toString());

    req.close();
  }
}


      

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org