public void testTermNonDefault() { String aField = config.getDimConfig("a").indexFieldName; Term termA = DrillDownQuery.term(aField, "a"); assertEquals(new Term(aField, "a"), termA); String bField = config.getDimConfig("b").indexFieldName; Term termB = DrillDownQuery.term(bField, "b"); assertEquals(new Term(bField, "b"), termB); }
/** * Note: if you use a counting {@link Facets} implementation, you can amortize the sampled counts * by calling this method. Uses the {@link FacetsConfig} and the {@link IndexSearcher} to * determine the upper bound for each facet value. */ public FacetResult amortizeFacetCounts( FacetResult res, FacetsConfig config, IndexSearcher searcher) throws IOException { if (res == null || totalHits <= sampleSize) { return res; } LabelAndValue[] fixedLabelValues = new LabelAndValue[res.labelValues.length]; IndexReader reader = searcher.getIndexReader(); DimConfig dimConfig = config.getDimConfig(res.dim); // +2 to prepend dimension, append child label String[] childPath = new String[res.path.length + 2]; childPath[0] = res.dim; System.arraycopy(res.path, 0, childPath, 1, res.path.length); // reuse for (int i = 0; i < res.labelValues.length; i++) { childPath[res.path.length + 1] = res.labelValues[i].label; String fullPath = FacetsConfig.pathToString(childPath, childPath.length); int max = reader.docFreq(new Term(dimConfig.indexFieldName, fullPath)); int correctedCount = (int) (res.labelValues[i].value.doubleValue() / samplingRate); correctedCount = Math.min(max, correctedCount); fixedLabelValues[i] = new LabelAndValue(res.labelValues[i].label, correctedCount); } // cap the total count on the total number of non-deleted documents in the reader int correctedTotalCount = res.value.intValue(); if (correctedTotalCount > 0) { correctedTotalCount = Math.min(reader.numDocs(), (int) (res.value.doubleValue() / samplingRate)); } return new FacetResult( res.dim, res.path, correctedTotalCount, fixedLabelValues, res.childCount); }