Search in sources :

Example 1 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project Solbase by Photobucket.

the class SolbaseDispatchFilter method handleAdminRequest.

@SuppressWarnings({ "unused", "unchecked" })
private void handleAdminRequest(HttpServletRequest req, ServletResponse response, SolrRequestHandler handler, SolrQueryRequest solrReq) throws IOException {
    SolrQueryResponse solrResp = new SolrQueryResponse();
    final NamedList<Object> responseHeader = new SimpleOrderedMap<Object>();
    solrResp.add("responseHeader", responseHeader);
    NamedList<Object> toLog = solrResp.getToLog();
    toLog.add("webapp", req.getContextPath());
    toLog.add("path", solrReq.getContext().get("path"));
    toLog.add("params", "{" + solrReq.getParamString() + "}");
    handler.handleRequest(solrReq, solrResp);
    SolrCore.setResponseHeaderValues(handler, solrReq, solrResp);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < toLog.size(); i++) {
        String name = toLog.getName(i);
        Object val = toLog.getVal(i);
        sb.append(name).append("=").append(val).append(" ");
    }
    QueryResponseWriter respWriter = SolrCore.DEFAULT_RESPONSE_WRITERS.get(solrReq.getParams().get(CommonParams.WT));
    if (respWriter == null)
        respWriter = SolrCore.DEFAULT_RESPONSE_WRITERS.get("standard");
    writeResponse(solrResp, response, respWriter, solrReq, Method.getMethod(req.getMethod()));
}
Also used : SolrQueryResponse(org.apache.solr.request.SolrQueryResponse) QueryResponseWriter(org.apache.solr.request.QueryResponseWriter) BinaryQueryResponseWriter(org.apache.solr.request.BinaryQueryResponseWriter) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 2 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SystemInfoHandlerTest method testMagickGetter.

public void testMagickGetter() throws Exception {
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    // make one directly
    SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
    info.add("name", os.getName());
    info.add("version", os.getVersion());
    info.add("arch", os.getArch());
    // make another using MetricUtils.addMXBeanMetrics()
    SimpleOrderedMap<Object> info2 = new SimpleOrderedMap<>();
    MetricUtils.addMXBeanMetrics(os, OperatingSystemMXBean.class, null, (k, v) -> {
        info2.add(k, ((Gauge) v).getValue());
    });
    // make sure they got the same thing
    for (String p : Arrays.asList("name", "version", "arch")) {
        assertEquals(info.get(p), info2.get(p));
    }
}
Also used : SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 3 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class TolerantUpdateProcessorTest method assertAddsSucceedWithErrors.

private void assertAddsSucceedWithErrors(String chain, final Collection<SolrInputDocument> docs, SolrParams requestParams, String... idsShouldFail) throws IOException {
    SolrQueryResponse response = add(chain, requestParams, docs);
    @SuppressWarnings("unchecked") List<SimpleOrderedMap<String>> errors = (List<SimpleOrderedMap<String>>) response.getResponseHeader().get("errors");
    assertNotNull(errors);
    assertEquals("number of errors", idsShouldFail.length, errors.size());
    Set<String> addErrorIdsExpected = new HashSet<String>(Arrays.asList(idsShouldFail));
    for (SimpleOrderedMap<String> err : errors) {
        assertEquals("this method only expects 'add' errors", "ADD", err.get("type"));
        String id = err.get("id");
        assertNotNull("null err id", id);
        assertTrue("unexpected id", addErrorIdsExpected.contains(id));
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) ArrayList(java.util.ArrayList) List(java.util.List) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashSet(java.util.HashSet)

Example 4 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class QueryResponse method extractGroupedInfo.

private void extractGroupedInfo(NamedList<Object> info) {
    if (info != null) {
        _groupResponse = new GroupResponse();
        int size = info.size();
        for (int i = 0; i < size; i++) {
            String fieldName = info.getName(i);
            Object fieldGroups = info.getVal(i);
            SimpleOrderedMap<Object> simpleOrderedMap = (SimpleOrderedMap<Object>) fieldGroups;
            Object oMatches = simpleOrderedMap.get("matches");
            Object oNGroups = simpleOrderedMap.get("ngroups");
            Object oGroups = simpleOrderedMap.get("groups");
            Object queryCommand = simpleOrderedMap.get("doclist");
            if (oMatches == null) {
                continue;
            }
            if (oGroups != null) {
                Integer iMatches = (Integer) oMatches;
                ArrayList<Object> groupsArr = (ArrayList<Object>) oGroups;
                GroupCommand groupedCommand;
                if (oNGroups != null) {
                    Integer iNGroups = (Integer) oNGroups;
                    groupedCommand = new GroupCommand(fieldName, iMatches, iNGroups);
                } else {
                    groupedCommand = new GroupCommand(fieldName, iMatches);
                }
                for (Object oGrp : groupsArr) {
                    SimpleOrderedMap grpMap = (SimpleOrderedMap) oGrp;
                    Object sGroupValue = grpMap.get("groupValue");
                    SolrDocumentList doclist = (SolrDocumentList) grpMap.get("doclist");
                    Group group = new Group(sGroupValue != null ? sGroupValue.toString() : null, doclist);
                    groupedCommand.add(group);
                }
                _groupResponse.add(groupedCommand);
            } else if (queryCommand != null) {
                Integer iMatches = (Integer) oMatches;
                GroupCommand groupCommand;
                if (oNGroups != null) {
                    Integer iNGroups = (Integer) oNGroups;
                    groupCommand = new GroupCommand(fieldName, iMatches, iNGroups);
                } else {
                    groupCommand = new GroupCommand(fieldName, iMatches);
                }
                SolrDocumentList docList = (SolrDocumentList) queryCommand;
                groupCommand.add(new Group(fieldName, docList));
                _groupResponse.add(groupCommand);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 5 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class TestJavabinTupleStreamParser method testKnown.

public void testKnown() throws IOException {
    String payload = "{\n" + "  \"responseHeader\":{\n" + "    \"zkConnected\":true,\n" + "    \"status\":0,\n" + "    \"QTime\":46},\n" + "  \"response\":{\n" + "    \"numFound\":2,\n" + "    \"start\":0,\n" + "    \"docs\":[\n" + "      {\n" + "        \"id\":\"2\",\n" + "        \"a_s\":\"hello2\",\n" + "        \"a_i\":2,\n" + "        \"a_f\":0.0},\n" + "      {\n" + "        \"id\":\"3\",\n" + "        \"a_s\":\"hello3\",\n" + "        \"a_i\":3,\n" + "        \"a_f\":3.0}]}}";
    SimpleOrderedMap nl = convert2OrderedMap((Map) Utils.fromJSONString(payload));
    byte[] bytes = serialize(nl);
    JavabinTupleStreamParser parser = new JavabinTupleStreamParser(new ByteArrayInputStream(bytes), true);
    Map<String, Object> map = parser.next();
    assertEquals("2", map.get("id"));
    map = parser.next();
    assertEquals("3", map.get("id"));
    System.out.println();
    map = parser.next();
    assertNull(map);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) JavabinTupleStreamParser(org.apache.solr.client.solrj.io.stream.JavabinTupleStreamParser)

Aggregations

SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)131 NamedList (org.apache.solr.common.util.NamedList)69 ArrayList (java.util.ArrayList)36 SolrException (org.apache.solr.common.SolrException)32 Map (java.util.Map)27 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 IOException (java.io.IOException)19 List (java.util.List)19 HashMap (java.util.HashMap)18 SolrParams (org.apache.solr.common.params.SolrParams)16 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)16 SchemaField (org.apache.solr.schema.SchemaField)16 FieldType (org.apache.solr.schema.FieldType)14 BytesRef (org.apache.lucene.util.BytesRef)13 Test (org.junit.Test)13 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)12 SolrDocumentList (org.apache.solr.common.SolrDocumentList)11 HashSet (java.util.HashSet)10 SolrCore (org.apache.solr.core.SolrCore)10 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)9