|
@@ -53,7 +53,7 @@ import static org.elasticsearch.index.mapper.core.TypeParsers.parseMultiField;
|
|
|
public class StringFieldMapper extends FieldMapper implements AllFieldMapper.IncludeInAll {
|
|
|
|
|
|
public static final String CONTENT_TYPE = "string";
|
|
|
- private static final int POSITION_OFFSET_GAP_USE_ANALYZER = -1;
|
|
|
+ private static final int POSITION_INCREMENT_GAP_USE_ANALYZER = -1;
|
|
|
|
|
|
public static class Defaults {
|
|
|
public static final MappedFieldType FIELD_TYPE = new StringFieldType();
|
|
@@ -64,23 +64,25 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
|
|
|
// NOTE, when adding defaults here, make sure you add them in the builder
|
|
|
public static final String NULL_VALUE = null;
|
|
|
+
|
|
|
/**
|
|
|
- * Post 2.0 default for position_offset_gap. Set to 100 so that
|
|
|
+ * Post 2.0 default for position_increment_gap. Set to 100 so that
|
|
|
* phrase queries of reasonably high slop will not match across field
|
|
|
* values.
|
|
|
*/
|
|
|
- public static final int POSITION_OFFSET_GAP = 100;
|
|
|
- public static final int POSITION_OFFSET_GAP_PRE_2_0 = 0;
|
|
|
+ public static final int POSITION_INCREMENT_GAP = 100;
|
|
|
+ public static final int POSITION_INCREMENT_GAP_PRE_2_0 = 0;
|
|
|
+
|
|
|
public static final int IGNORE_ABOVE = -1;
|
|
|
|
|
|
/**
|
|
|
- * The default position_offset_gap for a particular version of Elasticsearch.
|
|
|
+ * The default position_increment_gap for a particular version of Elasticsearch.
|
|
|
*/
|
|
|
- public static int positionOffsetGap(Version version) {
|
|
|
+ public static int positionIncrementGap(Version version) {
|
|
|
if (version.before(Version.V_2_0_0_beta1)) {
|
|
|
- return POSITION_OFFSET_GAP_PRE_2_0;
|
|
|
+ return POSITION_INCREMENT_GAP_PRE_2_0;
|
|
|
}
|
|
|
- return POSITION_OFFSET_GAP;
|
|
|
+ return POSITION_INCREMENT_GAP;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -90,10 +92,10 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
|
|
|
/**
|
|
|
* The distance between tokens from different values in the same field.
|
|
|
- * POSITION_OFFSET_GAP_USE_ANALYZER means default to the analyzer's
|
|
|
- * setting which in turn defaults to Defaults.POSITION_OFFSET_GAP.
|
|
|
+ * POSITION_INCREMENT_GAP_USE_ANALYZER means default to the analyzer's
|
|
|
+ * setting which in turn defaults to Defaults.POSITION_INCREMENT_GAP.
|
|
|
*/
|
|
|
- protected int positionOffsetGap = POSITION_OFFSET_GAP_USE_ANALYZER;
|
|
|
+ protected int positionIncrementGap = POSITION_INCREMENT_GAP_USE_ANALYZER;
|
|
|
|
|
|
protected int ignoreAbove = Defaults.IGNORE_ABOVE;
|
|
|
|
|
@@ -108,8 +110,8 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public Builder positionOffsetGap(int positionOffsetGap) {
|
|
|
- this.positionOffsetGap = positionOffsetGap;
|
|
|
+ public Builder positionIncrementGap(int positionIncrementGap) {
|
|
|
+ this.positionIncrementGap = positionIncrementGap;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
@@ -125,10 +127,10 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
|
|
|
@Override
|
|
|
public StringFieldMapper build(BuilderContext context) {
|
|
|
- if (positionOffsetGap != POSITION_OFFSET_GAP_USE_ANALYZER) {
|
|
|
- fieldType.setIndexAnalyzer(new NamedAnalyzer(fieldType.indexAnalyzer(), positionOffsetGap));
|
|
|
- fieldType.setSearchAnalyzer(new NamedAnalyzer(fieldType.searchAnalyzer(), positionOffsetGap));
|
|
|
- fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionOffsetGap));
|
|
|
+ if (positionIncrementGap != POSITION_INCREMENT_GAP_USE_ANALYZER) {
|
|
|
+ fieldType.setIndexAnalyzer(new NamedAnalyzer(fieldType.indexAnalyzer(), positionIncrementGap));
|
|
|
+ fieldType.setSearchAnalyzer(new NamedAnalyzer(fieldType.searchAnalyzer(), positionIncrementGap));
|
|
|
+ fieldType.setSearchQuoteAnalyzer(new NamedAnalyzer(fieldType.searchQuoteAnalyzer(), positionIncrementGap));
|
|
|
}
|
|
|
// if the field is not analyzed, then by default, we should omit norms and have docs only
|
|
|
// index options, as probably what the user really wants
|
|
@@ -147,7 +149,7 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
}
|
|
|
setupFieldType(context);
|
|
|
StringFieldMapper fieldMapper = new StringFieldMapper(
|
|
|
- name, fieldType, defaultFieldType, positionOffsetGap, ignoreAbove,
|
|
|
+ name, fieldType, defaultFieldType, positionIncrementGap, ignoreAbove,
|
|
|
context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
|
|
|
fieldMapper.includeInAll(includeInAll);
|
|
|
return fieldMapper;
|
|
@@ -176,14 +178,15 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
}
|
|
|
builder.searchQuotedAnalyzer(analyzer);
|
|
|
iterator.remove();
|
|
|
- } else if (propName.equals("position_offset_gap")) {
|
|
|
- int newPositionOffsetGap = XContentMapValues.nodeIntegerValue(propNode, -1);
|
|
|
- if (newPositionOffsetGap < 0) {
|
|
|
- throw new MapperParsingException("positions_offset_gap less than 0 aren't allowed.");
|
|
|
+ } else if (propName.equals("position_increment_gap") ||
|
|
|
+ parserContext.indexVersionCreated().before(Version.V_2_0_0) && propName.equals("position_offset_gap")) {
|
|
|
+ int newPositionIncrementGap = XContentMapValues.nodeIntegerValue(propNode, -1);
|
|
|
+ if (newPositionIncrementGap < 0) {
|
|
|
+ throw new MapperParsingException("positions_increment_gap less than 0 aren't allowed.");
|
|
|
}
|
|
|
- builder.positionOffsetGap(newPositionOffsetGap);
|
|
|
+ builder.positionIncrementGap(newPositionIncrementGap);
|
|
|
// we need to update to actual analyzers if they are not set in this case...
|
|
|
- // so we can inject the position offset gap...
|
|
|
+ // so we can inject the position increment gap...
|
|
|
if (builder.fieldType().indexAnalyzer() == null) {
|
|
|
builder.fieldType().setIndexAnalyzer(parserContext.analysisService().defaultIndexAnalyzer());
|
|
|
}
|
|
@@ -240,17 +243,17 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
}
|
|
|
|
|
|
private Boolean includeInAll;
|
|
|
- private int positionOffsetGap;
|
|
|
+ private int positionIncrementGap;
|
|
|
private int ignoreAbove;
|
|
|
|
|
|
protected StringFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
|
|
|
- int positionOffsetGap, int ignoreAbove,
|
|
|
+ int positionIncrementGap, int ignoreAbove,
|
|
|
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
|
|
|
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
|
|
|
if (fieldType.tokenized() && fieldType.indexOptions() != NONE && fieldType().hasDocValues()) {
|
|
|
throw new MapperParsingException("Field [" + fieldType.names().fullName() + "] cannot be analyzed and have doc values");
|
|
|
}
|
|
|
- this.positionOffsetGap = positionOffsetGap;
|
|
|
+ this.positionIncrementGap = positionIncrementGap;
|
|
|
this.ignoreAbove = ignoreAbove;
|
|
|
}
|
|
|
|
|
@@ -278,8 +281,8 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public int getPositionOffsetGap() {
|
|
|
- return this.positionOffsetGap;
|
|
|
+ public int getPositionIncrementGap() {
|
|
|
+ return this.positionIncrementGap;
|
|
|
}
|
|
|
|
|
|
public int getIgnoreAbove() {
|
|
@@ -381,8 +384,8 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
|
|
|
builder.field("include_in_all", false);
|
|
|
}
|
|
|
|
|
|
- if (includeDefaults || positionOffsetGap != POSITION_OFFSET_GAP_USE_ANALYZER) {
|
|
|
- builder.field("position_offset_gap", positionOffsetGap);
|
|
|
+ if (includeDefaults || positionIncrementGap != POSITION_INCREMENT_GAP_USE_ANALYZER) {
|
|
|
+ builder.field("position_increment_gap", positionIncrementGap);
|
|
|
}
|
|
|
NamedAnalyzer searchQuoteAnalyzer = fieldType().searchQuoteAnalyzer();
|
|
|
if (searchQuoteAnalyzer != null && !searchQuoteAnalyzer.name().equals(fieldType().searchAnalyzer().name())) {
|