move bloom filter class to a more common package
This commit is contained in:
parent
c48c8fd974
commit
826b8bd742
|
@ -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;
|
|
@ -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.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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}.
|
||||
* </p>
|
||||
*/
|
||||
|
@ -104,7 +105,7 @@ public final class BloomFilterPostingsFormat extends PostingsFormat {
|
|||
public final class BloomFilteredFieldsProducer extends FieldsProducer {
|
||||
private FieldsProducer delegateFieldsProducer;
|
||||
HashMap<String, BloomFilter> bloomsByFieldName = new HashMap<String, BloomFilter>();
|
||||
|
||||
|
||||
// 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <tt>_uid</tt> 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 <tt>_uid</tt> saving up to
|
||||
* {@link Lucene41PostingsFormat} and it's files also for the <tt>_uid</tt> 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)) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue