private static void assertDocIdSetCacheable(IndexReader reader, Filter filter, boolean shouldCacheable) throws IOException { assertTrue(reader.getContext() instanceof AtomicReaderContext); AtomicReaderContext context = (AtomicReaderContext) reader.getContext(); final CachingWrapperFilter cacher = new CachingWrapperFilter(filter); final DocIdSet originalSet = filter.getDocIdSet(context, context.reader().getLiveDocs()); final DocIdSet cachedSet = cacher.getDocIdSet(context, context.reader().getLiveDocs()); if (originalSet == null) { assertNull(cachedSet); } if (cachedSet == null) { assertTrue(originalSet == null || originalSet.iterator() == null); } else { assertTrue(cachedSet.isCacheable()); assertEquals(shouldCacheable, originalSet.isCacheable()); //System.out.println("Original: "+originalSet.getClass().getName()+" -- cached: "+cachedSet.getClass().getName()); if (originalSet.isCacheable()) { assertEquals("Cached DocIdSet must be of same class like uncached, if cacheable", originalSet.getClass(), cachedSet.getClass()); } else { assertTrue("Cached DocIdSet must be an WAH8DocIdSet if the original one was not cacheable", cachedSet instanceof WAH8DocIdSet || cachedSet == null); } } }
/** * Default cache implementation: uses {@link WAH8DocIdSet}. */ protected DocIdSet cacheImpl(DocIdSetIterator iterator, AtomicReader reader) throws IOException { WAH8DocIdSet.Builder builder = new WAH8DocIdSet.Builder(); builder.add(iterator); return builder.build(); }