diff -u solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java --- solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java (working copy) +++ solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java (working copy) @@ -178,8 +178,6 @@ fieldNames = r.getFieldNames(IndexReader.FieldOption.ALL); - // TODO: don't do this until its safe - setFilterRandomAccessThreshold(0); // do this at the end since an exception in the constructor means we won't close numOpens.incrementAndGet(); } diff -u lucene/src/java/org/apache/lucene/search/FilteredQuery.java lucene/src/java/org/apache/lucene/search/FilteredQuery.java --- lucene/src/java/org/apache/lucene/search/FilteredQuery.java (working copy) +++ lucene/src/java/org/apache/lucene/search/FilteredQuery.java (working copy) @@ -116,6 +116,10 @@ } final int firstFilterDoc = filterIter.nextDoc(); + if (firstFilterDoc == DocIdSetIterator.NO_MORE_DOCS) { + return null; + } + final Bits filterAcceptDocs = filterDocIdSet.bits(); final boolean useRandomAccess = (filterAcceptDocs != null && firstFilterDoc < searcher.getFilterRandomAccessThreshold()); diff -u lucene/src/java/org/apache/lucene/search/DocIdSet.java lucene/src/java/org/apache/lucene/search/DocIdSet.java --- lucene/src/java/org/apache/lucene/search/DocIdSet.java (working copy) +++ lucene/src/java/org/apache/lucene/search/DocIdSet.java (working copy) @@ -61,9 +61,19 @@ * are no docs that match. */ public abstract DocIdSetIterator iterator() throws IOException; - /** Optionally provides a {@link Bits} interface for random access. - * Returns {@code null}, if this DocIdSet does not support random access. - * The default implementation does not provide random access */ + /** Optionally provides a {@link Bits} interface for random access + * to matching documents. + * @return {@code null}, if this {@code DocIdSet} does not support random access. + * In contrast to {@link #iterator()}, a return value of {@code null} + * does not imply that no documents match the filter! + * The default implementation does not provide random access, so you + * only need to implement this method if your DocIdSet can + * guarantee random access to every docid in O(1) time without + * external disk access (as {@link Bits} interface cannot throw + * {@link IOException}). This is generally true for bit sets + * like {@link org.apache.lucene.util.FixedBitSet}, which return + * itsself if they are used as {@code DocIdSet}. + */ public Bits bits() throws IOException { return null; }