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()));
}
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));
}
}
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));
}
}
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);
}
}
}
}
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);
}
Aggregations