Search in sources :

Example 6 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class SmileWriterTest method testTypes.

@Test
public void testTypes() throws IOException {
    SolrQueryRequest req = req("dummy");
    SolrQueryResponse rsp = new SolrQueryResponse();
    rsp.add("data1", Float.NaN);
    rsp.add("data2", Double.NEGATIVE_INFINITY);
    rsp.add("data3", Float.POSITIVE_INFINITY);
    SmileResponseWriter smileResponseWriter = new SmileResponseWriter();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    smileResponseWriter.write(baos, req, rsp);
    Map m = (Map) decodeSmile(new ByteArrayInputStream(baos.toByteArray()));
    CharArr out = new CharArr();
    JSONWriter jsonWriter = new JSONWriter(out, 2);
    // indentation by default
    jsonWriter.setIndentSize(-1);
    jsonWriter.write(m);
    String s = new String(Utils.toUTF8(out), StandardCharsets.UTF_8);
    assertEquals(s, "{\"data1\":NaN,\"data2\":-Infinity,\"data3\":Infinity}");
    req.close();
}
Also used : JSONWriter(org.noggit.JSONWriter) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CharArr(org.noggit.CharArr) Test(org.junit.Test)

Example 7 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method printClusterStateInfo.

protected String printClusterStateInfo(String collection) throws Exception {
    cloudClient.getZkStateReader().forceUpdateCollection(collection);
    String cs = null;
    ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
    if (collection != null) {
        cs = clusterState.getCollection(collection).toString();
    } else {
        Map<String, DocCollection> map = clusterState.getCollectionsMap();
        CharArr out = new CharArr();
        new JSONWriter(out, 2).write(map);
        cs = out.toString();
    }
    return cs;
}
Also used : JSONWriter(org.noggit.JSONWriter) ClusterState(org.apache.solr.common.cloud.ClusterState) DocCollection(org.apache.solr.common.cloud.DocCollection) CharArr(org.noggit.CharArr)

Example 8 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class SolrTestCaseJ4 method jsonDelId.

/** Creates a JSON delete command from an id list */
public static String jsonDelId(Object... ids) {
    CharArr out = new CharArr();
    try {
        out.append('{');
        boolean first = true;
        for (Object id : ids) {
            if (first)
                first = false;
            else
                out.append(',');
            out.append("\"delete\":{\"id\":");
            out.append(JSONUtil.toJSON(id));
            out.append('}');
        }
        out.append('}');
    } catch (IOException e) {
    // should never happen
    }
    return out.toString();
}
Also used : IOException(java.io.IOException) CharArr(org.noggit.CharArr)

Example 9 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class SolrTestCaseJ4 method toJSON.

public static String toJSON(Doc doc) {
    CharArr out = new CharArr();
    try {
        out.append("{\"add\":{\"doc\":{");
        boolean firstField = true;
        for (Fld fld : doc.fields) {
            if (firstField)
                firstField = false;
            else
                out.append(',');
            JSONUtil.writeString(fld.ftype.fname, 0, fld.ftype.fname.length(), out);
            out.append(':');
            if (fld.vals.size() > 1) {
                out.append('[');
            }
            boolean firstVal = true;
            for (Comparable val : fld.vals) {
                if (firstVal)
                    firstVal = false;
                else
                    out.append(',');
                out.append(JSONUtil.toJSON(val));
            }
            if (fld.vals.size() > 1) {
                out.append(']');
            }
        }
        out.append("}}}");
    } catch (IOException e) {
    // should never happen
    }
    return out.toString();
}
Also used : IOException(java.io.IOException) CharArr(org.noggit.CharArr)

Example 10 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class SolrTestCaseJ4 method json.

/** Creates JSON from a SolrInputDocument.  Doesn't currently handle boosts.
   *  @see #json(SolrInputDocument,CharArr)
   */
public static String json(SolrInputDocument doc) {
    CharArr out = new CharArr();
    json(doc, out);
    return out.toString();
}
Also used : CharArr(org.noggit.CharArr)

Aggregations

CharArr (org.noggit.CharArr)14 IOException (java.io.IOException)6 JSONWriter (org.noggit.JSONWriter)6 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONParser (org.noggit.JSONParser)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 ClusterState (org.apache.solr.common.cloud.ClusterState)1 DocCollection (org.apache.solr.common.cloud.DocCollection)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 RTimer (org.apache.solr.util.RTimer)1 Test (org.junit.Test)1