new LongRange("90 or above", 90L, true, 100L, false),
new LongRange("over 1000", 1000L, false, Long.MAX_VALUE, false)));
final Set<String> dimSeen = new HashSet<String>();
DrillSideways ds = new DrillSideways(s, tr) {
@Override
protected FacetsAccumulator getDrillDownAccumulator(FacetSearchParams fsp) {
checkSeen(fsp);
return RangeFacetsAccumulatorWrapper.create(fsp, searcher.getIndexReader(), tr);
}
@Override
protected FacetsAccumulator getDrillSidewaysAccumulator(String dim, FacetSearchParams fsp) {
checkSeen(fsp);
return RangeFacetsAccumulatorWrapper.create(fsp, searcher.getIndexReader(), tr);
}
private void checkSeen(FacetSearchParams fsp) {
// Each dim should should up only once, across
// both drillDown and drillSideways requests:
for(FacetRequest fr : fsp.facetRequests) {
String dim = fr.categoryPath.components[0];
assertFalse("dim " + dim + " already seen", dimSeen.contains(dim));
dimSeen.add(dim);
}
}
@Override
protected boolean scoreSubDocsAtOnce() {
return random().nextBoolean();
}
};
// First search, no drill downs:
DrillDownQuery ddq = new DrillDownQuery(FacetIndexingParams.DEFAULT, new MatchAllDocsQuery());
DrillSidewaysResult dsr = ds.search(null, ddq, 10, fsp);
assertEquals(100, dsr.hits.totalHits);
assertEquals(2, dsr.facetResults.size());
assertEquals("dim (0)\n b (75)\n a (25)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(0)));
assertEquals("field (0)\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(1)));
// Second search, drill down on dim=b:
ddq = new DrillDownQuery(FacetIndexingParams.DEFAULT, new MatchAllDocsQuery());
ddq.add(new CategoryPath("dim", "b"));
dimSeen.clear();
dsr = ds.search(null, ddq, 10, fsp);
assertEquals(75, dsr.hits.totalHits);
assertEquals(2, dsr.facetResults.size());
assertEquals("dim (0)\n b (75)\n a (25)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(0)));
assertEquals("field (0)\n less than 10 (7)\n less than or equal to 10 (8)\n over 90 (7)\n 90 or above (8)\n over 1000 (0)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(1)));
// Third search, drill down on "less than or equal to 10":
ddq = new DrillDownQuery(FacetIndexingParams.DEFAULT, new MatchAllDocsQuery());
ddq.add("field", NumericRangeQuery.newLongRange("field", 0L, 10L, true, true));
dimSeen.clear();
dsr = ds.search(null, ddq, 10, fsp);
assertEquals(11, dsr.hits.totalHits);
assertEquals(2, dsr.facetResults.size());
assertEquals("dim (0)\n b (8)\n a (3)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(0)));
assertEquals("field (0)\n less than 10 (10)\n less than or equal to 10 (11)\n over 90 (9)\n 90 or above (10)\n over 1000 (0)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(1)));