have DocSet implement Bits interface

This commit is contained in:
Shay Banon 2011-11-29 23:52:58 +02:00
parent a21c0829c7
commit 6c552b4187
15 changed files with 59 additions and 25 deletions

View File

@ -41,7 +41,11 @@ public class AllDocSet extends DocSet {
return true; return true;
} }
@Override public boolean get(int doc) throws IOException { @Override public int length() {
return maxDoc;
}
@Override public boolean get(int doc) {
return doc < maxDoc; return doc < maxDoc;
} }

View File

@ -36,13 +36,20 @@ public class AndDocSet extends DocSet {
this.sets = sets; this.sets = sets;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
for (DocSet s : sets) { for (DocSet s : sets) {
if (!s.get(doc)) return false; if (!s.get(doc)) return false;
} }
return true; return true;
} }
@Override public int length() {
if (sets.isEmpty()) {
return 0;
}
return sets.get(0).length();
}
@Override public boolean isCacheable() { @Override public boolean isCacheable() {
// not cacheable, the reason is that by default, when constructing the filter, it is not cacheable, // not cacheable, the reason is that by default, when constructing the filter, it is not cacheable,
// so if someone wants it to be cacheable, we might as well construct a cached version of the result // so if someone wants it to be cacheable, we might as well construct a cached version of the result

View File

@ -21,16 +21,17 @@ package org.elasticsearch.common.lucene.docset;
import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.util.Bits;
import java.io.IOException; import java.io.IOException;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public abstract class DocSet extends DocIdSet { public abstract class DocSet extends DocIdSet implements Bits {
public static final DocSet EMPTY_DOC_SET = new DocSet() { public static final DocSet EMPTY_DOC_SET = new DocSet() {
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
return false; return false;
} }
@ -45,9 +46,13 @@ public abstract class DocSet extends DocIdSet {
@Override public long sizeInBytes() { @Override public long sizeInBytes() {
return 0; return 0;
} }
@Override public int length() {
return 0;
}
}; };
public abstract boolean get(int doc) throws IOException; public abstract boolean get(int doc);
public abstract long sizeInBytes(); public abstract long sizeInBytes();
} }

View File

@ -44,11 +44,15 @@ public class FixedBitDocSet extends DocSet {
return true; return true;
} }
@Override public int length() {
return set.length();
}
public FixedBitSet set() { public FixedBitSet set() {
return set; return set;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
return set.get(doc); return set.get(doc);
} }

View File

@ -38,6 +38,10 @@ public abstract class GetDocSet extends DocSet {
return 0; return 0;
} }
@Override public int length() {
return maxDoc;
}
@Override public DocIdSetIterator iterator() throws IOException { @Override public DocIdSetIterator iterator() throws IOException {
return new DocIdSetIterator() { return new DocIdSetIterator() {
private int doc = -1; private int doc = -1;

View File

@ -19,8 +19,6 @@
package org.elasticsearch.common.lucene.docset; package org.elasticsearch.common.lucene.docset;
import java.io.IOException;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
@ -40,7 +38,7 @@ public class NotDocSet extends GetDocSet {
// return set.isCacheable(); // return set.isCacheable();
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
return !set.get(doc); return !set.get(doc);
} }

View File

@ -45,6 +45,10 @@ public class OpenBitDocSet extends DocSet {
this.set = new OpenBitSetDISI(disi, numBits); this.set = new OpenBitSetDISI(disi, numBits);
} }
@Override public int length() {
return set.length();
}
@Override public boolean isCacheable() { @Override public boolean isCacheable() {
return true; return true;
} }
@ -53,7 +57,7 @@ public class OpenBitDocSet extends DocSet {
return set; return set;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
return set.fastGet(doc); return set.fastGet(doc);
} }

View File

@ -36,13 +36,20 @@ public class OrDocSet extends DocSet {
this.sets = sets; this.sets = sets;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
for (DocSet s : sets) { for (DocSet s : sets) {
if (s.get(doc)) return true; if (s.get(doc)) return true;
} }
return false; return false;
} }
@Override public int length() {
if (sets.isEmpty()) {
return 0;
}
return sets.get(0).length();
}
@Override public boolean isCacheable() { @Override public boolean isCacheable() {
// not cacheable, the reason is that by default, when constructing the filter, it is not cacheable, // not cacheable, the reason is that by default, when constructing the filter, it is not cacheable,
// so if someone wants it to be cacheable, we might as well construct a cached version of the result // so if someone wants it to be cacheable, we might as well construct a cached version of the result

View File

@ -54,7 +54,7 @@ public class LimitFilter extends NoCacheFilter {
this.limit = limit; this.limit = limit;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (++counter > limit) { if (++counter > limit) {
return false; return false;
} }

View File

@ -22,6 +22,7 @@ package org.elasticsearch.index.query;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.common.collect.Maps; import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
@ -174,7 +175,7 @@ public class ScriptFilterParser implements FilterParser {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
searchScript.setNextDocId(doc); searchScript.setNextDocId(doc);
Object val = searchScript.run(); Object val = searchScript.run();
if (val == null) { if (val == null) {
@ -186,7 +187,7 @@ public class ScriptFilterParser implements FilterParser {
if (val instanceof Number) { if (val instanceof Number) {
return ((Number) val).longValue() != 0; return ((Number) val).longValue() != 0;
} }
throw new IOException("Can't handle type [" + val + "] in script filter"); throw new ElasticSearchIllegalArgumentException("Can't handle type [" + val + "] in script filter");
} }
} }
} }

View File

@ -152,7 +152,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }
@ -209,7 +209,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }
@ -265,7 +265,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }
@ -321,7 +321,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }
@ -381,7 +381,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }
@ -441,7 +441,7 @@ public abstract class NumericRangeFieldDataFilter<T> extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }

View File

@ -173,7 +173,7 @@ public class GeoDistanceFilter extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }

View File

@ -192,7 +192,7 @@ public class GeoDistanceRangeFilter extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }

View File

@ -76,7 +76,7 @@ public class GeoPolygonFilter extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }

View File

@ -91,7 +91,7 @@ public class InMemoryGeoBoundingBoxFilter extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }
@ -139,7 +139,7 @@ public class InMemoryGeoBoundingBoxFilter extends Filter {
return false; return false;
} }
@Override public boolean get(int doc) throws IOException { @Override public boolean get(int doc) {
if (!fieldData.hasValue(doc)) { if (!fieldData.hasValue(doc)) {
return false; return false;
} }