> Thanks for the information. However, I still have one more > problem. I am > iterating over the values of the NamedList. I have 2 > values, one > being 'responseHeader' and the other one being 'grouped'. I > would like to > access some information stored within the grouped section, > which has > data structured like so: > > grouped={attr_directory={matches=4,groups=[{groupValue=C:\Users\rvassallo\Desktop\Index,doclist={numFound=2,start=0,docs=[SolrDocument[{attr_meta=[Author, > kcook, Last-Modified, 2011-03-02T14:14:18Z... > > With the 'get("group")' method I am only able to access the > entire > '{attr_directory={matches=4,g...' section. Is there some > functionality which > allows me to get other data? Something like this for > instance: > 'get("group.matches")' or maybe > 'get(group.attr_directory.matches)' (which > will yield the value of 4), or do I need to process the > String that the > 'get("...")' returns to get what I need? > > Thanks :)
I think accessing the relevant portion in a NamedList is troublesome. I suggest you to look at existing codes in solrJ. e.g. How facet info is extracted from NamedList. I am sending you the piece of code that I used to access grouped info. Hopefully It can give you some idea. NamedList signature = (NamedList) groupedInfo.get("attr_directory"); if (signature == null) return new ArrayList(0); matches.append(signature.get("matches")); @SuppressWarnings("unchecked") ArrayList<NamedList> groups = (ArrayList<NamedList>) signature.get("groups"); ArrayList<> resultItems = new ArrayList<>(groups.size()); StringBuilder builder = new StringBuilder(); for (NamedList res : groups) { ResultItem resultItem = null; String hash = null; Integer found = null; for (int i = 0; i < res.size(); i++) { String n = res.getName(i); Object o = res.getVal(i); if ("groupValue".equals(n)) { hash = (String) o; } else if ("doclist".equals(n)) { DocList docList = (DocList) o; found = docList.matches(); try { final SolrDocumentList list = SolrPluginUtils.docListToSolrDocumentList(docList, searcher, fields, null); builder.setLength(0); if (list.size() > 0) resultItem = solrDocumentToResultItem(list.get(0), debug); for (final SolrDocument document : list) builder.append(document.getFieldValue("id")).append(','); } catch (final IOException e) { LOG.error("Unexpected Error", e); } } } if (found != null && found > 1 && resultItem != null) { resultItem.setHash(hash); resultItem.setFound(found); builder.setLength(builder.length() - 1); resultItem.setId(builder.toString()); } // debug resultItems.add(resultItem); } return resultItems;