Skip to content

Commit 66d93e4

Browse files
committed
have DocSet implement Bits interface
1 parent 7dc3028 commit 66d93e4

15 files changed

+59
-25
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public AllDocSet(int maxDoc) {
4141
return true;
4242
}
4343

44-
@Override public boolean get(int doc) throws IOException {
44+
@Override public int length() {
45+
return maxDoc;
46+
}
47+
48+
@Override public boolean get(int doc) {
4549
return doc < maxDoc;
4650
}
4751

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ public AndDocSet(List<DocSet> sets) {
3636
this.sets = sets;
3737
}
3838

39-
@Override public boolean get(int doc) throws IOException {
39+
@Override public boolean get(int doc) {
4040
for (DocSet s : sets) {
4141
if (!s.get(doc)) return false;
4242
}
4343
return true;
4444
}
4545

46+
@Override public int length() {
47+
if (sets.isEmpty()) {
48+
return 0;
49+
}
50+
return sets.get(0).length();
51+
}
52+
4653
@Override public boolean isCacheable() {
4754
// not cacheable, the reason is that by default, when constructing the filter, it is not cacheable,
4855
// so if someone wants it to be cacheable, we might as well construct a cached version of the result

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@
2121

2222
import org.apache.lucene.search.DocIdSet;
2323
import org.apache.lucene.search.DocIdSetIterator;
24+
import org.apache.lucene.util.Bits;
2425

2526
import java.io.IOException;
2627

2728
/**
2829
* @author kimchy (shay.banon)
2930
*/
30-
public abstract class DocSet extends DocIdSet {
31+
public abstract class DocSet extends DocIdSet implements Bits {
3132

3233
public static final DocSet EMPTY_DOC_SET = new DocSet() {
33-
@Override public boolean get(int doc) throws IOException {
34+
@Override public boolean get(int doc) {
3435
return false;
3536
}
3637

@@ -45,9 +46,13 @@ public abstract class DocSet extends DocIdSet {
4546
@Override public long sizeInBytes() {
4647
return 0;
4748
}
49+
50+
@Override public int length() {
51+
return 0;
52+
}
4853
};
4954

50-
public abstract boolean get(int doc) throws IOException;
55+
public abstract boolean get(int doc);
5156

5257
public abstract long sizeInBytes();
5358
}

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/FixedBitDocSet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ public FixedBitDocSet(int numBits) {
4444
return true;
4545
}
4646

47+
@Override public int length() {
48+
return set.length();
49+
}
50+
4751
public FixedBitSet set() {
4852
return set;
4953
}
5054

51-
@Override public boolean get(int doc) throws IOException {
55+
@Override public boolean get(int doc) {
5256
return set.get(doc);
5357
}
5458

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/GetDocSet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ protected GetDocSet(int maxDoc) {
3838
return 0;
3939
}
4040

41+
@Override public int length() {
42+
return maxDoc;
43+
}
44+
4145
@Override public DocIdSetIterator iterator() throws IOException {
4246
return new DocIdSetIterator() {
4347
private int doc = -1;

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package org.elasticsearch.common.lucene.docset;
2121

22-
import java.io.IOException;
23-
2422
/**
2523
* @author kimchy (shay.banon)
2624
*/
@@ -40,7 +38,7 @@ public NotDocSet(DocSet set, int max) {
4038
// return set.isCacheable();
4139
}
4240

43-
@Override public boolean get(int doc) throws IOException {
41+
@Override public boolean get(int doc) {
4442
return !set.get(doc);
4543
}
4644

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public OpenBitDocSet(DocIdSetIterator disi, int numBits) throws IOException {
4545
this.set = new OpenBitSetDISI(disi, numBits);
4646
}
4747

48+
@Override public int length() {
49+
return set.length();
50+
}
51+
4852
@Override public boolean isCacheable() {
4953
return true;
5054
}
@@ -53,7 +57,7 @@ public OpenBitSet set() {
5357
return set;
5458
}
5559

56-
@Override public boolean get(int doc) throws IOException {
60+
@Override public boolean get(int doc) {
5761
return set.fastGet(doc);
5862
}
5963

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ public OrDocSet(List<DocSet> sets) {
3636
this.sets = sets;
3737
}
3838

39-
@Override public boolean get(int doc) throws IOException {
39+
@Override public boolean get(int doc) {
4040
for (DocSet s : sets) {
4141
if (s.get(doc)) return true;
4242
}
4343
return false;
4444
}
4545

46+
@Override public int length() {
47+
if (sets.isEmpty()) {
48+
return 0;
49+
}
50+
return sets.get(0).length();
51+
}
52+
4653
@Override public boolean isCacheable() {
4754
// not cacheable, the reason is that by default, when constructing the filter, it is not cacheable,
4855
// so if someone wants it to be cacheable, we might as well construct a cached version of the result

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public LimitDocSet(int maxDoc, int limit) {
5454
this.limit = limit;
5555
}
5656

57-
@Override public boolean get(int doc) throws IOException {
57+
@Override public boolean get(int doc) {
5858
if (++counter > limit) {
5959
return false;
6060
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/query/ScriptFilterParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.lucene.index.IndexReader;
2323
import org.apache.lucene.search.DocIdSet;
2424
import org.apache.lucene.search.Filter;
25+
import org.elasticsearch.ElasticSearchIllegalArgumentException;
2526
import org.elasticsearch.ElasticSearchIllegalStateException;
2627
import org.elasticsearch.common.collect.Maps;
2728
import org.elasticsearch.common.inject.Inject;
@@ -174,7 +175,7 @@ public ScriptDocSet(IndexReader reader, SearchScript searchScript) {
174175
return false;
175176
}
176177

177-
@Override public boolean get(int doc) throws IOException {
178+
@Override public boolean get(int doc) {
178179
searchScript.setNextDocId(doc);
179180
Object val = searchScript.run();
180181
if (val == null) {
@@ -186,7 +187,7 @@ public ScriptDocSet(IndexReader reader, SearchScript searchScript) {
186187
if (val instanceof Number) {
187188
return ((Number) val).longValue() != 0;
188189
}
189-
throw new IOException("Can't handle type [" + val + "] in script filter");
190+
throw new ElasticSearchIllegalArgumentException("Can't handle type [" + val + "] in script filter");
190191
}
191192
}
192193
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/search/NumericRangeFieldDataFilter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static NumericRangeFieldDataFilter<Byte> newByteRange(FieldDataCache fiel
152152
return false;
153153
}
154154

155-
@Override public boolean get(int doc) throws IOException {
155+
@Override public boolean get(int doc) {
156156
if (!fieldData.hasValue(doc)) {
157157
return false;
158158
}
@@ -209,7 +209,7 @@ public static NumericRangeFieldDataFilter<Short> newShortRange(FieldDataCache fi
209209
return false;
210210
}
211211

212-
@Override public boolean get(int doc) throws IOException {
212+
@Override public boolean get(int doc) {
213213
if (!fieldData.hasValue(doc)) {
214214
return false;
215215
}
@@ -265,7 +265,7 @@ public static NumericRangeFieldDataFilter<Integer> newIntRange(FieldDataCache fi
265265
return false;
266266
}
267267

268-
@Override public boolean get(int doc) throws IOException {
268+
@Override public boolean get(int doc) {
269269
if (!fieldData.hasValue(doc)) {
270270
return false;
271271
}
@@ -321,7 +321,7 @@ public static NumericRangeFieldDataFilter<Long> newLongRange(FieldDataCache fiel
321321
return false;
322322
}
323323

324-
@Override public boolean get(int doc) throws IOException {
324+
@Override public boolean get(int doc) {
325325
if (!fieldData.hasValue(doc)) {
326326
return false;
327327
}
@@ -381,7 +381,7 @@ public static NumericRangeFieldDataFilter<Float> newFloatRange(FieldDataCache fi
381381
return false;
382382
}
383383

384-
@Override public boolean get(int doc) throws IOException {
384+
@Override public boolean get(int doc) {
385385
if (!fieldData.hasValue(doc)) {
386386
return false;
387387
}
@@ -441,7 +441,7 @@ public static NumericRangeFieldDataFilter<Double> newDoubleRange(FieldDataCache
441441
return false;
442442
}
443443

444-
@Override public boolean get(int doc) throws IOException {
444+
@Override public boolean get(int doc) {
445445
if (!fieldData.hasValue(doc)) {
446446
return false;
447447
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public GeoDistanceDocSet(int maxDoc, GeoPointFieldData fieldData, GeoDistance.Fi
173173
return false;
174174
}
175175

176-
@Override public boolean get(int doc) throws IOException {
176+
@Override public boolean get(int doc) {
177177
if (!fieldData.hasValue(doc)) {
178178
return false;
179179
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceRangeFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public GeoDistanceRangeDocSet(int maxDoc, GeoPointFieldData fieldData, GeoDistan
192192
return false;
193193
}
194194

195-
@Override public boolean get(int doc) throws IOException {
195+
@Override public boolean get(int doc) {
196196
if (!fieldData.hasValue(doc)) {
197197
return false;
198198
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoPolygonFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public GeoPolygonDocSet(int maxDoc, GeoPointFieldData fieldData, Point[] points)
7676
return false;
7777
}
7878

79-
@Override public boolean get(int doc) throws IOException {
79+
@Override public boolean get(int doc) {
8080
if (!fieldData.hasValue(doc)) {
8181
return false;
8282
}

modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/InMemoryGeoBoundingBoxFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public Meridian180GeoBoundingBoxDocSet(int maxDoc, GeoPointFieldData fieldData,
9191
return false;
9292
}
9393

94-
@Override public boolean get(int doc) throws IOException {
94+
@Override public boolean get(int doc) {
9595
if (!fieldData.hasValue(doc)) {
9696
return false;
9797
}
@@ -139,7 +139,7 @@ public GeoBoundingBoxDocSet(int maxDoc, GeoPointFieldData fieldData, Point topLe
139139
return false;
140140
}
141141

142-
@Override public boolean get(int doc) throws IOException {
142+
@Override public boolean get(int doc) {
143143
if (!fieldData.hasValue(doc)) {
144144
return false;
145145
}

0 commit comments

Comments
 (0)