pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / search / DocIdSet.java
1 package org.apache.lucene.search;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 import java.io.IOException;
21
22 /**
23  * A DocIdSet contains a set of doc ids. Implementing classes must
24  * only implement {@link #iterator} to provide access to the set. 
25  */
26 public abstract class DocIdSet {
27
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() {
30     
31     private final DocIdSetIterator iterator = new DocIdSetIterator() {
32       @Override
33       public int advance(int target) throws IOException { return NO_MORE_DOCS; }
34       @Override
35       public int docID() { return NO_MORE_DOCS; }
36       @Override
37       public int nextDoc() throws IOException { return NO_MORE_DOCS; }
38     };
39     
40     @Override
41     public DocIdSetIterator iterator() {
42       return iterator;
43     }
44     
45     @Override
46     public boolean isCacheable() {
47       return true;
48     }
49   };
50     
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;
56
57   /**
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>.
63    */
64   public boolean isCacheable() {
65     return false;
66   }
67 }