keep the uidField around so we don't have to look it up

This commit is contained in:
Shay Banon 2012-11-15 12:52:58 +01:00
parent e2e25ffea3
commit c09ee82ef5
8 changed files with 34 additions and 20 deletions

View File

@ -120,6 +120,10 @@ public class UidField extends Field {
private long version;
public UidField(String uid) {
this(UidFieldMapper.NAME, uid, 0);
}
public UidField(String name, String uid, long version) {
super(name, UidFieldMapper.Defaults.UID_FIELD_TYPE);
this.uid = uid;

View File

@ -37,6 +37,11 @@ import java.util.Map;
*/
public class BloomFilterPostingsFormatProvider extends AbstractPostingsFormatProvider {
public static final class Defaults {
public static final float MAX_SATURATION = 0.1f;
public static final float SATURATION_LIMIT = 0.9f;
}
private final float desiredMaxSaturation;
private final float saturationLimit;
private final PostingsFormatProvider delegate;
@ -45,8 +50,8 @@ public class BloomFilterPostingsFormatProvider extends AbstractPostingsFormatPro
@Inject
public BloomFilterPostingsFormatProvider(@IndexSettings Settings indexSettings, @Nullable Map<String, Factory> postingFormatFactories, @Assisted String name, @Assisted Settings postingsFormatSettings) {
super(name);
this.desiredMaxSaturation = postingsFormatSettings.getAsFloat("desired_max_saturation", 0.1f);
this.saturationLimit = postingsFormatSettings.getAsFloat("saturation_limit", 0.9f);
this.desiredMaxSaturation = postingsFormatSettings.getAsFloat("desired_max_saturation", Defaults.MAX_SATURATION);
this.saturationLimit = postingsFormatSettings.getAsFloat("saturation_limit", Defaults.SATURATION_LIMIT);
this.delegate = Helper.lookup(indexSettings, postingsFormatSettings.get("delegate"), postingFormatFactories);
this.postingsFormat = new BloomFilteringPostingsFormat(
delegate.get(),
@ -71,11 +76,15 @@ public class BloomFilterPostingsFormatProvider extends AbstractPostingsFormatPro
return postingsFormat;
}
static class CustomBloomFilterFactory extends BloomFilterFactory {
public static class CustomBloomFilterFactory extends BloomFilterFactory {
private final float desiredMaxSaturation;
private final float saturationLimit;
public CustomBloomFilterFactory() {
this(Defaults.MAX_SATURATION, Defaults.SATURATION_LIMIT);
}
CustomBloomFilterFactory(float desiredMaxSaturation, float saturationLimit) {
this.desiredMaxSaturation = desiredMaxSaturation;
this.saturationLimit = saturationLimit;

View File

@ -45,9 +45,9 @@ public class PostingFormats {
buildInPostingFormatsX.put("memory", new PreBuiltPostingsFormatProvider.Factory("memory", new MemoryPostingsFormat()));
// LUCENE UPGRADE: Need to change this to the relevant ones on a lucene upgrade
buildInPostingFormatsX.put("pulsing", new PreBuiltPostingsFormatProvider.Factory("pulsing", new Pulsing40PostingsFormat()));
buildInPostingFormatsX.put("bloom_pulsing", new PreBuiltPostingsFormatProvider.Factory("bloom_pulsing", new BloomFilteringPostingsFormat(new Pulsing40PostingsFormat())));
buildInPostingFormatsX.put("bloom_pulsing", new PreBuiltPostingsFormatProvider.Factory("bloom_pulsing", new BloomFilteringPostingsFormat(new Pulsing40PostingsFormat(), new BloomFilterPostingsFormatProvider.CustomBloomFilterFactory())));
buildInPostingFormatsX.put("default", new PreBuiltPostingsFormatProvider.Factory("default", new Lucene40PostingsFormat()));
buildInPostingFormatsX.put("bloom_default", new PreBuiltPostingsFormatProvider.Factory("bloom_default", new BloomFilteringPostingsFormat(new Lucene40PostingsFormat())));
buildInPostingFormatsX.put("bloom_default", new PreBuiltPostingsFormatProvider.Factory("bloom_default", new BloomFilteringPostingsFormat(new Lucene40PostingsFormat(), new BloomFilterPostingsFormatProvider.CustomBloomFilterFactory())));
builtInPostingFormats = buildInPostingFormatsX.immutableMap();
}

View File

@ -38,7 +38,6 @@ import org.elasticsearch.index.VersionType;
import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.internal.UidFieldMapper;
import org.elasticsearch.index.shard.IndexShardComponent;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.translog.Translog;
@ -475,7 +474,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
}
public UidField uidField() {
return (UidField) doc.rootDoc().getField(UidFieldMapper.NAME);
return doc.uid();
}
@ -603,7 +602,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
}
public UidField uidField() {
return (UidField) doc.rootDoc().getField(UidFieldMapper.NAME);
return doc.uid();
}
public Index startTime(long startTime) {

View File

@ -24,6 +24,7 @@ import org.apache.lucene.document.Document;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.lucene.all.AllEntries;
import org.elasticsearch.common.lucene.uid.UidField;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.analysis.AnalysisService;
@ -65,7 +66,7 @@ public class ParseContext {
private DocumentMapper.ParseListener listener;
private String uid;
private UidField uid;
private StringBuilder stringBuilder = new StringBuilder();
@ -218,14 +219,14 @@ public class ParseContext {
this.id = id;
}
public String uid() {
public UidField uid() {
return this.uid;
}
/**
* Really, just the uid mapper should set this.
*/
public void uid(String uid) {
public void uid(UidField uid) {
this.uid = uid;
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.lucene.uid.UidField;
import java.util.Arrays;
import java.util.List;
@ -31,7 +32,7 @@ import java.util.List;
*/
public class ParsedDocument {
private final String uid;
private final UidField uid;
private final String id;
@ -54,10 +55,10 @@ public class ParsedDocument {
private String parent;
public ParsedDocument(String uid, String id, String type, String routing, long timestamp, long ttl, Document document, Analyzer analyzer, BytesReference source, boolean mappingsModified) {
this(uid, id, type, routing, timestamp, ttl, Arrays.asList(document), analyzer, source, mappingsModified);
this(new UidField(uid), id, type, routing, timestamp, ttl, Arrays.asList(document), analyzer, source, mappingsModified);
}
public ParsedDocument(String uid, String id, String type, String routing, long timestamp, long ttl, List<Document> documents, Analyzer analyzer, BytesReference source, boolean mappingsModified) {
public ParsedDocument(UidField uid, String id, String type, String routing, long timestamp, long ttl, List<Document> documents, Analyzer analyzer, BytesReference source, boolean mappingsModified) {
this.uid = uid;
this.id = id;
this.type = type;
@ -70,7 +71,7 @@ public class ParsedDocument {
this.mappingsModified = mappingsModified;
}
public String uid() {
public UidField uid() {
return this.uid;
}

View File

@ -165,12 +165,12 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
@Override
protected Field parseCreateField(ParseContext context) throws IOException {
context.uid(Uid.createUid(context.stringBuilder(), context.type(), context.id()));
// so, caching uid stream and field is fine
// since we don't do any mapping parsing without immediate indexing
// and, when percolating, we don't index the uid
UidField field = fieldCache.get();
field.setUid(context.uid());
field.setUid(Uid.createUid(context.stringBuilder(), context.type(), context.id()));
context.uid(field);
return field; // version get updated by the engine
}

View File

@ -295,7 +295,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
long startTime = System.nanoTime();
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type());
ParsedDocument doc = docMapper.parse(source);
return new Engine.Create(docMapper, docMapper.uidMapper().term(doc.uid()), doc).startTime(startTime);
return new Engine.Create(docMapper, docMapper.uidMapper().term(doc.uid().uid()), doc).startTime(startTime);
}
@Override
@ -316,7 +316,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
long startTime = System.nanoTime();
DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type());
ParsedDocument doc = docMapper.parse(source);
return new Engine.Index(docMapper, docMapper.uidMapper().term(doc.uid()), doc).startTime(startTime);
return new Engine.Index(docMapper, docMapper.uidMapper().term(doc.uid().uid()), doc).startTime(startTime);
}
@Override
@ -371,7 +371,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
query = filterQueryIfNeeded(query, types);
Filter aliasFilter = indexAliasesService.aliasFilter(filteringAliases);
Filter parentFilter = mapperService.hasNested() ? indexCache.filter().cache(NonNestedDocsFilter.INSTANCE) : null;
Filter parentFilter = mapperService.hasNested() ? indexCache.filter().cache(NonNestedDocsFilter.INSTANCE) : null;
return new Engine.DeleteByQuery(query, querySource, filteringAliases, aliasFilter, parentFilter, types).startTime(startTime);
}