1 package org.apache.lucene.search;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
23 * A DocIdSet contains a set of doc ids. Implementing classes must
24 * only implement {@link #iterator} to provide access to the set.
26 public abstract class DocIdSet {
28 /** An empty {@code DocIdSet} instance for easy use, e.g. in Filters that hit no documents. */
29 public static final DocIdSet EMPTY_DOCIDSET = new DocIdSet() {
31 private final DocIdSetIterator iterator = new DocIdSetIterator() {
33 public int advance(int target) throws IOException { return NO_MORE_DOCS; }
35 public int docID() { return NO_MORE_DOCS; }
37 public int nextDoc() throws IOException { return NO_MORE_DOCS; }
41 public DocIdSetIterator iterator() {
46 public boolean isCacheable() {
51 /** Provides a {@link DocIdSetIterator} to access the set.
52 * This implementation can return <code>null</code> or
53 * <code>{@linkplain #EMPTY_DOCIDSET}.iterator()</code> if there
54 * are no docs that match. */
55 public abstract DocIdSetIterator iterator() throws IOException;
58 * This method is a hint for {@link CachingWrapperFilter}, if this <code>DocIdSet</code>
59 * should be cached without copying it into a BitSet. The default is to return
60 * <code>false</code>. If you have an own <code>DocIdSet</code> implementation
61 * that does its iteration very effective and fast without doing disk I/O,
62 * override this method and return <code>true</here>.
64 public boolean isCacheable() {