void fillBucket(SimpleOrderedMap<Object> bucket, Query q, DocSet result) throws IOException { boolean needDocSet = freq.getFacetStats().size() > 0 || freq.getSubFacets().size() > 0; // TODO: always collect counts or not??? int count; if (result != null) { count = result.size(); } else if (needDocSet) { if (q == null) { result = fcontext.base; // result.incref(); // OFF-HEAP } else { result = fcontext.searcher.getDocSet(q, fcontext.base); } count = result.size(); } else { if (q == null) { count = fcontext.base.size(); } else { count = fcontext.searcher.numDocs(q, fcontext.base); } } try { processStats(bucket, result, count); processSubs(bucket, q, result); } finally { if (result != null) { // result.decref(); // OFF-HEAP result = null; } } }
void processSubs(SimpleOrderedMap<Object> response, Query filter, DocSet domain) throws IOException { // TODO: what if a zero bucket has a sub-facet with an exclusion that would yield results? // should we check for domain-altering exclusions, or even ask the sub-facet for // it's domain and then only skip it if it's 0? if (domain == null || domain.size() == 0 && !freq.processEmpty) { return; } for (Map.Entry<String, FacetRequest> sub : freq.getSubFacets().entrySet()) { // make a new context for each sub-facet since they can change the domain FacetContext subContext = fcontext.sub(filter, domain); FacetProcessor subProcessor = sub.getValue().createFacetProcessor(subContext); if (fcontext.getDebugInfo() != null) { // if fcontext.debugInfo != null, it means rb.debug() == true FacetDebugInfo fdebug = new FacetDebugInfo(); subContext.setDebugInfo(fdebug); fcontext.getDebugInfo().addChild(fdebug); fdebug.setReqDescription(sub.getValue().getFacetDescription()); fdebug.setProcessor(subProcessor.getClass().getSimpleName()); if (subContext.filter != null) fdebug.setFilter(subContext.filter.toString()); final RTimer timer = new RTimer(); subProcessor.process(); long timeElapsed = (long) timer.getTime(); fdebug.setElapse(timeElapsed); fdebug.putInfoItem("domainSize", (long) subContext.base.size()); } else { subProcessor.process(); } response.add(sub.getKey(), subProcessor.getResponse()); } }