mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
lucene 4: Converted remaining Mappers to FieldType API
This commit is contained in:
parent
549900a082
commit
f444ed4dff
@ -21,8 +21,8 @@ package org.elasticsearch.common.lucene.all;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
import org.apache.lucene.document.AbstractField;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -31,22 +31,21 @@ import java.io.Reader;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AllField extends AbstractField {
|
||||
public class AllField extends Field {
|
||||
|
||||
private final AllEntries allEntries;
|
||||
|
||||
private final Analyzer analyzer;
|
||||
|
||||
public AllField(String name, Field.Store store, Field.TermVector termVector, AllEntries allEntries, Analyzer analyzer) {
|
||||
super(name, store, Field.Index.ANALYZED, termVector);
|
||||
|
||||
public AllField(String name, AllEntries allEntries, Analyzer analyzer, FieldType fieldType) {
|
||||
super(name, fieldType);
|
||||
this.allEntries = allEntries;
|
||||
this.analyzer = analyzer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringValue() {
|
||||
if (isStored()) {
|
||||
if (fieldType().stored()) {
|
||||
return allEntries.buildText();
|
||||
}
|
||||
return null;
|
||||
|
@ -24,6 +24,7 @@ import com.google.common.collect.Maps;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
@ -154,7 +155,9 @@ public class DocumentMapper implements ToXContent {
|
||||
if (indexSettings != null) {
|
||||
String idIndexed = indexSettings.get("index.mapping._id.indexed");
|
||||
if (idIndexed != null && Booleans.parseBoolean(idIndexed, false)) {
|
||||
idFieldMapper = new IdFieldMapper(Field.Index.NOT_ANALYZED);
|
||||
FieldType fieldType = new FieldType(IdFieldMapper.Defaults.ID_FIELD_TYPE);
|
||||
fieldType.setTokenized(false);
|
||||
idFieldMapper = new IdFieldMapper(fieldType);
|
||||
}
|
||||
}
|
||||
this.rootMappers.put(IdFieldMapper.class, idFieldMapper);
|
||||
|
@ -113,7 +113,7 @@ public interface FieldMapper<T> {
|
||||
* Creates a new index term based on the provided value.
|
||||
*/
|
||||
public Term createIndexNameTerm(String value) {
|
||||
return indexNameTermFactory.createTerm(value);
|
||||
return new Term(indexName, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,27 +76,27 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T storeTermVectors(boolean termVectors) {
|
||||
public T storeTermVectors(boolean termVectors) {
|
||||
return super.storeTermVectors(termVectors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T storeTermVectorOffsets(boolean termVectorOffsets) {
|
||||
public T storeTermVectorOffsets(boolean termVectorOffsets) {
|
||||
return super.storeTermVectorOffsets(termVectorOffsets);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T storeTermVectorPositions(boolean termVectorPositions) {
|
||||
public T storeTermVectorPositions(boolean termVectorPositions) {
|
||||
return super.storeTermVectorPositions(termVectorPositions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T storeTermVectorPayloads(boolean termVectorPayloads) {
|
||||
public T storeTermVectorPayloads(boolean termVectorPayloads) {
|
||||
return super.storeTermVectorPayloads(termVectorPayloads);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T tokenized(boolean tokenized) {
|
||||
public T tokenized(boolean tokenized) {
|
||||
return super.tokenized(tokenized);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.elasticsearch.index.mapper.geo;
|
||||
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
@ -73,7 +73,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
|
||||
public static class Defaults {
|
||||
public static final ContentPath.Type PATH_TYPE = ContentPath.Type.FULL;
|
||||
public static final Field.Store STORE = Field.Store.NO;
|
||||
public static final boolean STORE = false;
|
||||
public static final boolean ENABLE_LATLON = false;
|
||||
public static final boolean ENABLE_GEOHASH = false;
|
||||
public static final int PRECISION = GeoHashUtils.PRECISION;
|
||||
@ -81,6 +81,16 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
public static final boolean NORMALIZE_LON = true;
|
||||
public static final boolean VALIDATE_LAT = true;
|
||||
public static final boolean VALIDATE_LON = true;
|
||||
|
||||
public static final FieldType GEO_STRING_FIELD_TYPE = new FieldType(StringFieldMapper.Defaults.STRING_FIELD_TYPE);
|
||||
|
||||
static {
|
||||
GEO_STRING_FIELD_TYPE.setIndexed(true);
|
||||
GEO_STRING_FIELD_TYPE.setTokenized(false);
|
||||
GEO_STRING_FIELD_TYPE.setOmitNorms(true);
|
||||
GEO_STRING_FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_ONLY);
|
||||
GEO_STRING_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends Mapper.Builder<Builder, GeoPointFieldMapper> {
|
||||
@ -95,7 +105,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
|
||||
private int precision = Defaults.PRECISION;
|
||||
|
||||
private Field.Store store = Defaults.STORE;
|
||||
private boolean store = Defaults.STORE;
|
||||
|
||||
boolean validateLat = Defaults.VALIDATE_LAT;
|
||||
boolean validateLon = Defaults.VALIDATE_LON;
|
||||
@ -132,7 +142,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder store(Field.Store store) {
|
||||
public Builder store(boolean store) {
|
||||
this.store = store;
|
||||
return this;
|
||||
}
|
||||
@ -143,7 +153,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
context.path().pathType(pathType);
|
||||
|
||||
GeoStringFieldMapper geoStringMapper = new GeoStringFieldMapper.Builder(name)
|
||||
.index(Field.Index.NOT_ANALYZED).omitNorms(true).indexOptions(IndexOptions.DOCS_ONLY).includeInAll(false).store(store).build(context);
|
||||
.includeInAll(false).store(store).build(context);
|
||||
|
||||
|
||||
DoubleFieldMapper latMapper = null;
|
||||
@ -162,7 +172,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
}
|
||||
StringFieldMapper geohashMapper = null;
|
||||
if (enableGeoHash) {
|
||||
geohashMapper = stringField(Names.GEOHASH).index(Field.Index.NOT_ANALYZED).includeInAll(false).omitNorms(true).indexOptions(IndexOptions.DOCS_ONLY).build(context);
|
||||
geohashMapper = stringField(Names.GEOHASH).index(true).tokenized(false).includeInAll(false).omitNorms(true).indexOptions(IndexOptions.DOCS_ONLY).build(context);
|
||||
}
|
||||
context.path().remove();
|
||||
|
||||
@ -493,8 +503,8 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
if (enableGeoHash != Defaults.ENABLE_GEOHASH) {
|
||||
builder.field("geohash", enableGeoHash);
|
||||
}
|
||||
if (geoStringMapper.store() != Defaults.STORE) {
|
||||
builder.field("store", geoStringMapper.store().name().toLowerCase());
|
||||
if (geoStringMapper.stored() != Defaults.STORE) {
|
||||
builder.field("store", geoStringMapper.stored());
|
||||
}
|
||||
if (precision != Defaults.PRECISION) {
|
||||
builder.field("geohash_precision", precision);
|
||||
@ -534,7 +544,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
protected String nullValue = Defaults.NULL_VALUE;
|
||||
|
||||
public Builder(String name) {
|
||||
super(name);
|
||||
super(name, new FieldType(GeoPointFieldMapper.Defaults.GEO_STRING_FIELD_TYPE));
|
||||
builder = this;
|
||||
}
|
||||
|
||||
@ -552,7 +562,7 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
@Override
|
||||
public GeoStringFieldMapper build(BuilderContext context) {
|
||||
GeoStringFieldMapper fieldMapper = new GeoStringFieldMapper(buildNames(context),
|
||||
index, store, termVector, boost, omitNorms, indexOptions, nullValue,
|
||||
boost, fieldType, nullValue,
|
||||
indexAnalyzer, searchAnalyzer);
|
||||
fieldMapper.includeInAll(includeInAll);
|
||||
return fieldMapper;
|
||||
@ -561,8 +571,8 @@ public class GeoPointFieldMapper implements Mapper, ArrayValueMapperParser {
|
||||
|
||||
GeoPointFieldMapper geoMapper;
|
||||
|
||||
public GeoStringFieldMapper(Names names, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, IndexOptions indexOptions, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
super(names, index, store, termVector, boost, omitNorms, indexOptions, nullValue, indexAnalyzer, searchAnalyzer);
|
||||
public GeoStringFieldMapper(Names names, float boost, FieldType fieldType, String nullValue, NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer) {
|
||||
super(names, boost, fieldType, nullValue, indexAnalyzer, searchAnalyzer);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper.internal;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Query;
|
||||
@ -62,6 +63,14 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
public static final String NAME = AllFieldMapper.NAME;
|
||||
public static final String INDEX_NAME = AllFieldMapper.NAME;
|
||||
public static final boolean ENABLED = true;
|
||||
|
||||
public static final FieldType ALL_FIELD_TYPE = new FieldType();
|
||||
|
||||
static {
|
||||
ALL_FIELD_TYPE.setIndexed(true);
|
||||
ALL_FIELD_TYPE.setTokenized(true);
|
||||
ALL_FIELD_TYPE.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder extends AbstractFieldMapper.Builder<Builder, AllFieldMapper> {
|
||||
@ -72,7 +81,7 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
boolean autoBoost = false;
|
||||
|
||||
public Builder() {
|
||||
super(Defaults.NAME);
|
||||
super(Defaults.NAME, new FieldType(Defaults.ALL_FIELD_TYPE));
|
||||
builder = this;
|
||||
indexName = Defaults.INDEX_NAME;
|
||||
}
|
||||
@ -82,29 +91,13 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder store(Field.Store store) {
|
||||
return super.store(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder termVector(Field.TermVector termVector) {
|
||||
return super.termVector(termVector);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder indexAnalyzer(NamedAnalyzer indexAnalyzer) {
|
||||
return super.indexAnalyzer(indexAnalyzer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Builder searchAnalyzer(NamedAnalyzer searchAnalyzer) {
|
||||
return super.searchAnalyzer(searchAnalyzer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllFieldMapper build(BuilderContext context) {
|
||||
return new AllFieldMapper(name, store, termVector, omitNorms, indexOptions,
|
||||
// In case the mapping overrides these
|
||||
fieldType.setIndexed(true);
|
||||
fieldType.setTokenized(true);
|
||||
|
||||
return new AllFieldMapper(name, fieldType,
|
||||
indexAnalyzer, searchAnalyzer, enabled, autoBoost);
|
||||
}
|
||||
}
|
||||
@ -137,13 +130,12 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
private volatile boolean autoBoost;
|
||||
|
||||
public AllFieldMapper() {
|
||||
this(Defaults.NAME, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.OMIT_NORMS, Defaults.INDEX_OPTIONS, null, null, Defaults.ENABLED, false);
|
||||
this(Defaults.NAME, new FieldType(Defaults.ALL_FIELD_TYPE), null, null, Defaults.ENABLED, false);
|
||||
}
|
||||
|
||||
protected AllFieldMapper(String name, Field.Store store, Field.TermVector termVector, boolean omitNorms, IndexOptions indexOptions,
|
||||
protected AllFieldMapper(String name, FieldType fieldType,
|
||||
NamedAnalyzer indexAnalyzer, NamedAnalyzer searchAnalyzer, boolean enabled, boolean autoBoost) {
|
||||
super(new Names(name, name, name, name), Field.Index.ANALYZED, store, termVector, 1.0f, omitNorms, indexOptions, indexAnalyzer,
|
||||
searchAnalyzer);
|
||||
super(new Names(name, name, name, name), 1.0f, fieldType, indexAnalyzer, searchAnalyzer);
|
||||
this.enabled = enabled;
|
||||
this.autoBoost = autoBoost;
|
||||
|
||||
@ -158,7 +150,7 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
if (!autoBoost) {
|
||||
return new TermQuery(term);
|
||||
}
|
||||
if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) {
|
||||
if (fieldType.indexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) {
|
||||
return new AllTermQuery(term);
|
||||
}
|
||||
return new TermQuery(term);
|
||||
@ -209,7 +201,7 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
}
|
||||
|
||||
Analyzer analyzer = findAnalyzer(context);
|
||||
return new AllField(names.indexName(), store, termVector, context.allEntries(), analyzer);
|
||||
return new AllField(names.indexName(), context.allEntries(), analyzer, fieldType);
|
||||
}
|
||||
|
||||
private Analyzer findAnalyzer(ParseContext context) {
|
||||
@ -255,7 +247,9 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
// if all are defaults, no need to write it at all
|
||||
if (enabled == Defaults.ENABLED && store == Defaults.STORE && termVector == Defaults.TERM_VECTOR && indexAnalyzer == null && searchAnalyzer == null) {
|
||||
if (enabled == Defaults.ENABLED && stored() == Defaults.ALL_FIELD_TYPE.stored() &&
|
||||
storeTermVectors() == Defaults.ALL_FIELD_TYPE.storeTermVectors() &&
|
||||
indexAnalyzer == null && searchAnalyzer == null) {
|
||||
return builder;
|
||||
}
|
||||
builder.startObject(CONTENT_TYPE);
|
||||
@ -265,11 +259,20 @@ public class AllFieldMapper extends AbstractFieldMapper<Void> implements Interna
|
||||
if (autoBoost != false) {
|
||||
builder.field("auto_boost", autoBoost);
|
||||
}
|
||||
if (store != Defaults.STORE) {
|
||||
builder.field("store", store.name().toLowerCase());
|
||||
if (stored() != Defaults.ALL_FIELD_TYPE.stored()) {
|
||||
builder.field("store", stored());
|
||||
}
|
||||
if (termVector != Defaults.TERM_VECTOR) {
|
||||
builder.field("term_vector", termVector.name().toLowerCase());
|
||||
if (storeTermVectors() != Defaults.ALL_FIELD_TYPE.storeTermVectors()) {
|
||||
builder.field("store_term_vector", storeTermVectors());
|
||||
}
|
||||
if (storeTermVectorOffsets() != Defaults.ALL_FIELD_TYPE.storeTermVectorOffsets()) {
|
||||
builder.field("store_term_vector_offsets", storeTermVectorOffsets());
|
||||
}
|
||||
if (storeTermVectorPositions() != Defaults.ALL_FIELD_TYPE.storeTermVectorPositions()) {
|
||||
builder.field("store_term_vector_positions", storeTermVectorPositions());
|
||||
}
|
||||
if (storeTermVectorPayloads() != Defaults.ALL_FIELD_TYPE.storeTermVectorPayloads()) {
|
||||
builder.field("store_term_vector_payloads", storeTermVectorPayloads());
|
||||
}
|
||||
if (indexAnalyzer != null && searchAnalyzer != null && indexAnalyzer.name().equals(searchAnalyzer.name()) && !indexAnalyzer.name().startsWith("_")) {
|
||||
// same analyzers, output it once
|
||||
|
@ -22,8 +22,6 @@ package org.elasticsearch.index.mapper.ip;
|
||||
import org.apache.lucene.analysis.NumericTokenStream;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.FieldType;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.index.FieldInfo.IndexOptions;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
|
Loading…
x
Reference in New Issue
Block a user