From 826b8bd742cf423e25cdbd716f6311730089169a Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 14 Nov 2013 15:36:50 +0100 Subject: [PATCH] move bloom filter class to a more common package --- .../util}/BloomFilter.java | 2 +- .../BloomFilterPostingsFormat.java | 17 +++++++++-------- .../BloomFilterPostingsFormatProvider.java | 1 + .../ElasticSearch090PostingsFormat.java | 18 ++++++++---------- .../codec/postingsformat/PostingFormats.java | 1 + .../benchmark/bloom/BloomBench.java | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) rename src/main/java/org/elasticsearch/{index/codec/postingsformat => common/util}/BloomFilter.java (99%) diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilter.java b/src/main/java/org/elasticsearch/common/util/BloomFilter.java similarity index 99% rename from src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilter.java rename to src/main/java/org/elasticsearch/common/util/BloomFilter.java index b471b97e1a9..542238c108e 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilter.java +++ b/src/main/java/org/elasticsearch/common/util/BloomFilter.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.index.codec.postingsformat; +package org.elasticsearch.common.util; import com.google.common.math.LongMath; import com.google.common.primitives.Ints; diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java index 30026cc43f7..6e57e00cd83 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java +++ b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormat.java @@ -29,6 +29,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.RamUsageEstimator; import org.apache.lucene.util.automaton.CompiledAutomaton; +import org.elasticsearch.common.util.BloomFilter; import java.io.IOException; import java.util.*; @@ -42,7 +43,7 @@ import java.util.Map.Entry; * delegate PostingsFormat is used to record all other Postings data. *

*

- * This is a special bloom filter version, based on {@link BloomFilter} and inspired + * This is a special bloom filter version, based on {@link org.elasticsearch.common.util.BloomFilter} and inspired * by Lucene {@link org.apache.lucene.codecs.bloom.BloomFilteringPostingsFormat}. *

*/ @@ -104,7 +105,7 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { public final class BloomFilteredFieldsProducer extends FieldsProducer { private FieldsProducer delegateFieldsProducer; HashMap bloomsByFieldName = new HashMap(); - + // for internal use only FieldsProducer getDelegate() { return delegateFieldsProducer; @@ -126,7 +127,7 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { // Load the delegate postings format PostingsFormat delegatePostingsFormat = PostingsFormat.forName(bloomIn .readString()); - + this.delegateFieldsProducer = delegatePostingsFormat .fieldsProducer(state); int numBlooms = bloomIn.readInt(); @@ -186,9 +187,9 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { return RamUsageEstimator.sizeOf(this); } - + } - + public static final class BloomFilteredTerms extends Terms { private Terms delegateTerms; private BloomFilter filter; @@ -280,13 +281,13 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { this.reuse = reuse; this.filter = filter; } - + void reset(Terms others) { reuse = this.delegateTermsEnum; this.delegateTermsEnum = null; this.delegateTerms = others; } - + private TermsEnum getDelegate() throws IOException { if (delegateTermsEnum == null) { /* pull the iterator only if we really need it - @@ -383,7 +384,7 @@ public final class BloomFilterPostingsFormat extends PostingsFormat { // this.delegatePostingsFormat=delegatePostingsFormat; this.state = state; } - + // for internal use only FieldsConsumer getDelegate() { return delegateFieldsConsumer; diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormatProvider.java b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormatProvider.java index d4c7f259329..d6812668528 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormatProvider.java +++ b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormatProvider.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.assistedinject.Assisted; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.util.BloomFilter; import org.elasticsearch.index.settings.IndexSettings; import java.util.Map; diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/ElasticSearch090PostingsFormat.java b/src/main/java/org/elasticsearch/index/codec/postingsformat/ElasticSearch090PostingsFormat.java index a5b5f0b1d92..d0e5802457c 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/ElasticSearch090PostingsFormat.java +++ b/src/main/java/org/elasticsearch/index/codec/postingsformat/ElasticSearch090PostingsFormat.java @@ -18,9 +18,6 @@ */ package org.elasticsearch.index.codec.postingsformat; -import java.io.IOException; -import java.util.Iterator; - import org.apache.lucene.codecs.FieldsConsumer; import org.apache.lucene.codecs.FieldsProducer; import org.apache.lucene.codecs.PostingsFormat; @@ -29,26 +26,27 @@ import org.apache.lucene.codecs.lucene41.Lucene41PostingsFormat; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.SegmentWriteState; -import org.apache.lucene.index.Terms; +import org.elasticsearch.common.util.BloomFilter; import org.elasticsearch.index.codec.postingsformat.BloomFilterPostingsFormat.BloomFilteredFieldsConsumer; -import org.elasticsearch.index.codec.postingsformat.BloomFilterPostingsFormat.BloomFilteredFieldsProducer; import org.elasticsearch.index.mapper.internal.UidFieldMapper; +import java.io.IOException; + /** * This is the default postings format for ElasticSearch that special cases * the _uid field to use a bloom filter while all other fields * will use a {@link Lucene41PostingsFormat}. This format will reuse the underlying - * {@link Lucene41PostingsFormat} and it's files also for the _uid saving up to + * {@link Lucene41PostingsFormat} and it's files also for the _uid saving up to * 5 files per segment in the default case. */ public final class ElasticSearch090PostingsFormat extends PostingsFormat { private final BloomFilterPostingsFormat bloomPostings; - + public ElasticSearch090PostingsFormat() { super("es090"); bloomPostings = new BloomFilterPostingsFormat(new Lucene41PostingsFormat(), BloomFilter.Factory.DEFAULT); } - + public PostingsFormat getDefaultWrapped() { return bloomPostings.getDelegate(); } @@ -57,12 +55,12 @@ public final class ElasticSearch090PostingsFormat extends PostingsFormat { public FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException { final BloomFilteredFieldsConsumer fieldsConsumer = bloomPostings.fieldsConsumer(state); return new FieldsConsumer() { - + @Override public void close() throws IOException { fieldsConsumer.close(); } - + @Override public TermsConsumer addField(FieldInfo field) throws IOException { if (UidFieldMapper.NAME.equals(field.name)) { diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/PostingFormats.java b/src/main/java/org/elasticsearch/index/codec/postingsformat/PostingFormats.java index 4459dfeb67b..882eb18971d 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/PostingFormats.java +++ b/src/main/java/org/elasticsearch/index/codec/postingsformat/PostingFormats.java @@ -25,6 +25,7 @@ import org.apache.lucene.codecs.PostingsFormat; import org.apache.lucene.codecs.bloom.BloomFilteringPostingsFormat; import org.apache.lucene.codecs.memory.DirectPostingsFormat; import org.elasticsearch.common.collect.MapBuilder; +import org.elasticsearch.common.util.BloomFilter; /** * This class represents the set of Elasticsearch "build-in" diff --git a/src/test/java/org/elasticsearch/benchmark/bloom/BloomBench.java b/src/test/java/org/elasticsearch/benchmark/bloom/BloomBench.java index 73a65c5aec4..0a978068d70 100644 --- a/src/test/java/org/elasticsearch/benchmark/bloom/BloomBench.java +++ b/src/test/java/org/elasticsearch/benchmark/bloom/BloomBench.java @@ -5,7 +5,7 @@ import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.Strings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.SizeValue; -import org.elasticsearch.index.codec.postingsformat.BloomFilter; +import org.elasticsearch.common.util.BloomFilter; import java.security.SecureRandom;