From 6c552b4187e49696e81c12f10baa75304114dae0 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 29 Nov 2011 23:52:58 +0200 Subject: [PATCH] have DocSet implement Bits interface --- .../common/lucene/docset/AllDocSet.java | 6 +++++- .../common/lucene/docset/AndDocSet.java | 9 ++++++++- .../elasticsearch/common/lucene/docset/DocSet.java | 11 ++++++++--- .../common/lucene/docset/FixedBitDocSet.java | 6 +++++- .../common/lucene/docset/GetDocSet.java | 4 ++++ .../common/lucene/docset/NotDocSet.java | 4 +--- .../common/lucene/docset/OpenBitDocSet.java | 6 +++++- .../elasticsearch/common/lucene/docset/OrDocSet.java | 9 ++++++++- .../common/lucene/search/LimitFilter.java | 2 +- .../index/query/ScriptFilterParser.java | 5 +++-- .../index/search/NumericRangeFieldDataFilter.java | 12 ++++++------ .../index/search/geo/GeoDistanceFilter.java | 2 +- .../index/search/geo/GeoDistanceRangeFilter.java | 2 +- .../index/search/geo/GeoPolygonFilter.java | 2 +- .../search/geo/InMemoryGeoBoundingBoxFilter.java | 4 ++-- 15 files changed, 59 insertions(+), 25 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java index 69c5ef26f05..b0b325b31ba 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AllDocSet.java @@ -41,7 +41,11 @@ public class AllDocSet extends DocSet { 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; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java index 6df18f63f63..c252e5457f0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/AndDocSet.java @@ -36,13 +36,20 @@ public class AndDocSet extends DocSet { this.sets = sets; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { for (DocSet s : sets) { if (!s.get(doc)) return false; } return true; } + @Override public int length() { + if (sets.isEmpty()) { + return 0; + } + return sets.get(0).length(); + } + @Override public boolean isCacheable() { // 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 diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java index 5753dcc92d1..066bbb7ebed 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/DocSet.java @@ -21,16 +21,17 @@ package org.elasticsearch.common.lucene.docset; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.DocIdSetIterator; +import org.apache.lucene.util.Bits; import java.io.IOException; /** * @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() { - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { return false; } @@ -45,9 +46,13 @@ public abstract class DocSet extends DocIdSet { @Override public long sizeInBytes() { 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(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/FixedBitDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/FixedBitDocSet.java index 516d5664b5e..1e05b28756d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/FixedBitDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/FixedBitDocSet.java @@ -44,11 +44,15 @@ public class FixedBitDocSet extends DocSet { return true; } + @Override public int length() { + return set.length(); + } + public FixedBitSet set() { return set; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { return set.get(doc); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/GetDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/GetDocSet.java index 2496a3dee24..d76e6a6a55c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/GetDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/GetDocSet.java @@ -38,6 +38,10 @@ public abstract class GetDocSet extends DocSet { return 0; } + @Override public int length() { + return maxDoc; + } + @Override public DocIdSetIterator iterator() throws IOException { return new DocIdSetIterator() { private int doc = -1; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java index 523d94d36a0..87b556cbb7e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/NotDocSet.java @@ -19,8 +19,6 @@ package org.elasticsearch.common.lucene.docset; -import java.io.IOException; - /** * @author kimchy (shay.banon) */ @@ -40,7 +38,7 @@ public class NotDocSet extends GetDocSet { // return set.isCacheable(); } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { return !set.get(doc); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java index a96bac6a80e..08a883cb7ca 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OpenBitDocSet.java @@ -45,6 +45,10 @@ public class OpenBitDocSet extends DocSet { this.set = new OpenBitSetDISI(disi, numBits); } + @Override public int length() { + return set.length(); + } + @Override public boolean isCacheable() { return true; } @@ -53,7 +57,7 @@ public class OpenBitDocSet extends DocSet { return set; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { return set.fastGet(doc); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java index 8aac40ba6d2..e17abe30ec8 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/docset/OrDocSet.java @@ -36,13 +36,20 @@ public class OrDocSet extends DocSet { this.sets = sets; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { for (DocSet s : sets) { if (s.get(doc)) return true; } return false; } + @Override public int length() { + if (sets.isEmpty()) { + return 0; + } + return sets.get(0).length(); + } + @Override public boolean isCacheable() { // 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 diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java index bcfcb038fba..1b002f713c4 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java @@ -54,7 +54,7 @@ public class LimitFilter extends NoCacheFilter { this.limit = limit; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (++counter > limit) { return false; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/ScriptFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/ScriptFilterParser.java index dbc46df435d..ab543733f2a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/ScriptFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/ScriptFilterParser.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.Filter; +import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.common.collect.Maps; import org.elasticsearch.common.inject.Inject; @@ -174,7 +175,7 @@ public class ScriptFilterParser implements FilterParser { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { searchScript.setNextDocId(doc); Object val = searchScript.run(); if (val == null) { @@ -186,7 +187,7 @@ public class ScriptFilterParser implements FilterParser { if (val instanceof Number) { 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"); } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/NumericRangeFieldDataFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/NumericRangeFieldDataFilter.java index 98294f8b9e0..36a42846e63 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/NumericRangeFieldDataFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/NumericRangeFieldDataFilter.java @@ -152,7 +152,7 @@ public abstract class NumericRangeFieldDataFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } @@ -209,7 +209,7 @@ public abstract class NumericRangeFieldDataFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } @@ -265,7 +265,7 @@ public abstract class NumericRangeFieldDataFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } @@ -321,7 +321,7 @@ public abstract class NumericRangeFieldDataFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } @@ -381,7 +381,7 @@ public abstract class NumericRangeFieldDataFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } @@ -441,7 +441,7 @@ public abstract class NumericRangeFieldDataFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceFilter.java index f25630e4dc5..c5f65353bc7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceFilter.java @@ -173,7 +173,7 @@ public class GeoDistanceFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceRangeFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceRangeFilter.java index cd7fd7a3b41..32ec4a4a4b5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceRangeFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoDistanceRangeFilter.java @@ -192,7 +192,7 @@ public class GeoDistanceRangeFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoPolygonFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoPolygonFilter.java index 9be91c86826..67c1708b9c0 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoPolygonFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/GeoPolygonFilter.java @@ -76,7 +76,7 @@ public class GeoPolygonFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/InMemoryGeoBoundingBoxFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/InMemoryGeoBoundingBoxFilter.java index 11d09d25c3c..1b749a7d0d9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/InMemoryGeoBoundingBoxFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/search/geo/InMemoryGeoBoundingBoxFilter.java @@ -91,7 +91,7 @@ public class InMemoryGeoBoundingBoxFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; } @@ -139,7 +139,7 @@ public class InMemoryGeoBoundingBoxFilter extends Filter { return false; } - @Override public boolean get(int doc) throws IOException { + @Override public boolean get(int doc) { if (!fieldData.hasValue(doc)) { return false; }