use FieldMapper.Names for fieldNames, and not just fieldName as string

This commit is contained in:
Shay Banon 2013-01-18 13:45:10 +01:00
parent 7dc5cf9799
commit e0b280f9b3
9 changed files with 38 additions and 31 deletions

View File

@ -3,30 +3,31 @@ package org.elasticsearch.index.fielddata;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.settings.IndexSettings;
/**
*/
public abstract class AbstractIndexFieldData<FD extends AtomicFieldData> extends AbstractIndexComponent implements IndexFieldData<FD> {
private final String fieldName;
private final FieldMapper.Names fieldNames;
protected final FieldDataType fieldDataType;
protected final IndexFieldDataCache cache;
public AbstractIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) {
public AbstractIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) {
super(index, indexSettings);
this.fieldName = fieldName;
this.fieldNames = fieldNames;
this.fieldDataType = fieldDataType;
this.cache = cache;
}
@Override
public String getFieldName() {
return this.fieldName;
public FieldMapper.Names getFieldNames() {
return this.fieldNames;
}
@Override
public void clear() {
cache.clear(index, fieldName);
cache.clear(index, fieldNames.indexName());
}
}

View File

@ -26,6 +26,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexComponent;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.settings.IndexSettings;
/**
@ -35,7 +36,7 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
/**
* The field name.
*/
String getFieldName();
FieldMapper.Names getFieldNames();
/**
* Are the values ordered? (in ascending manner).
@ -72,6 +73,6 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
interface Builder {
IndexFieldData build(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType type, IndexFieldDataCache cache);
IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache);
}
}

View File

@ -32,6 +32,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.plain.ConcreteBytesRefIndexFieldData;
import org.elasticsearch.index.fielddata.plain.DoubleArrayIndexFieldData;
import org.elasticsearch.index.fielddata.plain.LongArrayIndexFieldData;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.settings.IndexSettings;
import java.util.concurrent.ConcurrentMap;
@ -86,7 +87,7 @@ public class IndexFieldDataService extends AbstractIndexComponent {
}
}
public <IFD extends IndexFieldData> IFD getForField(String fieldName, FieldDataType type) {
public <IFD extends IndexFieldData> IFD getForField(FieldMapper.Names fieldNames, FieldDataType type) {
IndexFieldData fieldData = loadedFieldData.get(type.getType());
if (fieldData == null) {
synchronized (loadedFieldData) {
@ -100,7 +101,7 @@ public class IndexFieldDataService extends AbstractIndexComponent {
builder = buildersByType.get(type.getType());
}
if (builder == null) {
throw new ElasticSearchIllegalArgumentException("failed to find field data builder for field " + fieldName + ", and type " + type);
throw new ElasticSearchIllegalArgumentException("failed to find field data builder for field " + fieldNames.fullName() + ", and type " + type);
}
IndexFieldDataCache cache;
@ -111,14 +112,14 @@ public class IndexFieldDataService extends AbstractIndexComponent {
} else if ("soft".equals(cacheType)) {
cache = new IndexFieldDataCache.Soft();
} else {
throw new ElasticSearchIllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
throw new ElasticSearchIllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldNames.fullName() + "]");
}
} else {
cache = new IndexFieldDataCache.Resident();
}
fieldData = builder.build(index, indexSettings, fieldName, type, cache);
loadedFieldData.put(fieldName, fieldData);
fieldData = builder.build(index, indexSettings, fieldNames, type, cache);
loadedFieldData.put(fieldNames.indexName(), fieldData);
}
}
}

View File

@ -43,7 +43,7 @@ public class BytesRefFieldComparatorSource extends IndexFieldData.XFieldComparat
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
assert fieldname.equals(indexFieldData.getFieldName());
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
if (indexFieldData.valuesOrdered() && indexFieldData instanceof IndexOrdinalFieldData) {
return new BytesRefOrdValComparator((IndexOrdinalFieldData) indexFieldData, numHits);
}

View File

@ -46,7 +46,7 @@ public class DoubleValuesComparatorSource extends IndexFieldData.XFieldComparato
@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
assert fieldname.equals(indexFieldData.getFieldName());
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
double dMissingValue;
if (missingValue == null || "_last".equals(missingValue)) {

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparator
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
import org.elasticsearch.index.fielddata.ordinals.SingleArrayOrdinals;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.settings.IndexSettings;
import java.util.ArrayList;
@ -41,13 +42,13 @@ public class ConcreteBytesRefIndexFieldData extends AbstractIndexFieldData<Concr
public static class Builder implements IndexFieldData.Builder {
@Override
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType type, IndexFieldDataCache cache) {
return new ConcreteBytesRefIndexFieldData(index, indexSettings, fieldName, type, cache);
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache) {
return new ConcreteBytesRefIndexFieldData(index, indexSettings, fieldNames, type, cache);
}
}
public ConcreteBytesRefIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) {
super(index, indexSettings, fieldName, fieldDataType, cache);
public ConcreteBytesRefIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) {
super(index, indexSettings, fieldNames, fieldDataType, cache);
}
@Override
@ -72,7 +73,7 @@ public class ConcreteBytesRefIndexFieldData extends AbstractIndexFieldData<Concr
public ConcreteBytesRefAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
AtomicReader reader = context.reader();
Terms terms = reader.terms(getFieldName());
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new ConcreteBytesRefAtomicFieldData(new BytesRef[1], new EmptyOrdinals(reader.maxDoc()));
}

View File

@ -31,6 +31,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.settings.IndexSettings;
import java.util.ArrayList;
@ -42,13 +43,13 @@ public class DoubleArrayIndexFieldData extends AbstractIndexFieldData<DoubleArra
public static class Builder implements IndexFieldData.Builder {
@Override
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType type, IndexFieldDataCache cache) {
return new DoubleArrayIndexFieldData(index, indexSettings, fieldName, type, cache);
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache) {
return new DoubleArrayIndexFieldData(index, indexSettings, fieldNames, type, cache);
}
}
public DoubleArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) {
super(index, indexSettings, fieldName, fieldDataType, cache);
public DoubleArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) {
super(index, indexSettings, fieldNames, fieldDataType, cache);
}
@Override
@ -80,7 +81,7 @@ public class DoubleArrayIndexFieldData extends AbstractIndexFieldData<DoubleArra
public DoubleArrayAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
AtomicReader reader = context.reader();
Terms terms = reader.terms(getFieldName());
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new DoubleArrayAtomicFieldData.Single(new double[0], 0);
}

View File

@ -31,6 +31,7 @@ import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.settings.IndexSettings;
import java.util.ArrayList;
@ -42,13 +43,13 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<LongArrayAto
public static class Builder implements IndexFieldData.Builder {
@Override
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType type, IndexFieldDataCache cache) {
return new LongArrayIndexFieldData(index, indexSettings, fieldName, type, cache);
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache) {
return new LongArrayIndexFieldData(index, indexSettings, fieldNames, type, cache);
}
}
public LongArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) {
super(index, indexSettings, fieldName, fieldDataType, cache);
public LongArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) {
super(index, indexSettings, fieldNames, fieldDataType, cache);
}
@Override
@ -80,7 +81,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<LongArrayAto
public LongArrayAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
AtomicReader reader = context.reader();
Terms terms = reader.terms(getFieldName());
Terms terms = reader.terms(getFieldNames().indexName());
if (terms == null) {
return new LongArrayAtomicFieldData.Single(new long[0], 0);
}

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.lucene.HashedBytesRef;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.fielddata.*;
import org.elasticsearch.index.mapper.FieldMapper;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -50,7 +51,7 @@ public abstract class AbstractFieldDataTests {
protected abstract FieldDataType getFieldDataType();
public <IFD extends IndexFieldData> IFD getForField(String fieldName) {
return ifdService.getForField(fieldName, getFieldDataType());
return ifdService.getForField(new FieldMapper.Names(fieldName), getFieldDataType());
}
@BeforeMethod