Skip to content

Commit

Permalink
Move stored flag from TextSearchInfo to MappedFieldType (#62717) (#62770
Browse files Browse the repository at this point in the history
)
  • Loading branch information
javanna committed Sep 23, 2020
1 parent b4ec821 commit 5ca86d5
Show file tree
Hide file tree
Showing 85 changed files with 260 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static final class RankFeatureFieldType extends MappedFieldType {
private final boolean positiveScoreImpact;

public RankFeatureFieldType(String name, Map<String, String> meta, boolean positiveScoreImpact) {
super(name, true, false, TextSearchInfo.NONE, meta);
super(name, true, false, false, TextSearchInfo.NONE, meta);
this.positiveScoreImpact = positiveScoreImpact;
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static final class RankFeatureMetaFieldType extends MappedFieldType {
public static final RankFeatureMetaFieldType INSTANCE = new RankFeatureMetaFieldType();

private RankFeatureMetaFieldType() {
super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap());
super(NAME, false, false, false, TextSearchInfo.NONE, Collections.emptyMap());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Mapper.Builder<?> parse(String name, Map<String, Object> node, ParserCont
public static final class RankFeaturesFieldType extends MappedFieldType {

public RankFeaturesFieldType(String name, Map<String, String> meta) {
super(name, false, false, TextSearchInfo.NONE, meta);
super(name, false, false, false, TextSearchInfo.NONE, meta);
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ protected List<Parameter<?>> getParameters() {

@Override
public ScaledFloatFieldMapper build(BuilderContext context) {
ScaledFloatFieldType type = new ScaledFloatFieldType(buildFullName(context), indexed.getValue(), hasDocValues.getValue(),
meta.getValue(), scalingFactor.getValue());
ScaledFloatFieldType type = new ScaledFloatFieldType(buildFullName(context), indexed.getValue(), stored.getValue(),
hasDocValues.getValue(), meta.getValue(), scalingFactor.getValue());
return new ScaledFloatFieldMapper(name, type, multiFieldsBuilder.build(this, context), copyTo.build(), this);
}
}
Expand All @@ -138,13 +138,14 @@ public static final class ScaledFloatFieldType extends SimpleMappedFieldType {

private final double scalingFactor;

public ScaledFloatFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta, double scalingFactor) {
super(name, indexed, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
public ScaledFloatFieldType(String name, boolean indexed, boolean stored, boolean hasDocValues,
Map<String, String> meta, double scalingFactor) {
super(name, indexed, stored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
this.scalingFactor = scalingFactor;
}

public ScaledFloatFieldType(String name, double scalingFactor) {
this(name, true, true, Collections.emptyMap(), scalingFactor);
this(name, true, false, true, Collections.emptyMap(), scalingFactor);
}

public double getScalingFactor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static class SearchAsYouTypeFieldType extends StringFieldType {

SearchAsYouTypeFieldType(String name, FieldType fieldType, SimilarityProvider similarity,
NamedAnalyzer searchAnalyzer, NamedAnalyzer searchQuoteAnalyzer, Map<String, String> meta) {
super(name, fieldType.indexOptions() != IndexOptions.NONE, false,
super(name, fieldType.indexOptions() != IndexOptions.NONE, fieldType.stored(), false,
new TextSearchInfo(fieldType, similarity, searchAnalyzer, searchQuoteAnalyzer), meta);
}

Expand Down Expand Up @@ -354,7 +354,7 @@ static final class PrefixFieldType extends StringFieldType {
final String parentField;

PrefixFieldType(String parentField, TextSearchInfo textSearchInfo, int minChars, int maxChars) {
super(parentField + PREFIX_FIELD_SUFFIX, true, false, textSearchInfo, Collections.emptyMap());
super(parentField + PREFIX_FIELD_SUFFIX, true, false, false, textSearchInfo, Collections.emptyMap());
this.minChars = minChars;
this.maxChars = maxChars;
this.parentField = parentField;
Expand Down Expand Up @@ -487,7 +487,7 @@ static class ShingleFieldType extends StringFieldType {
PrefixFieldType prefixFieldType;

ShingleFieldType(String name, int shingleSize, TextSearchInfo textSearchInfo) {
super(name, true, false, textSearchInfo, Collections.emptyMap());
super(name, true, false, false, textSearchInfo, Collections.emptyMap());
this.shingleSize = shingleSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testRangeQuery() throws IOException {
// this test checks that searching scaled floats yields the same results as
// searching doubles that are rounded to the closest half float
ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType(
"scaled_float", true, false, Collections.emptyMap(), 0.1 + randomDouble() * 100);
"scaled_float", true, false, false, Collections.emptyMap(), 0.1 + randomDouble() * 100);
Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
final int numDocs = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static class MetaJoinFieldType extends StringFieldType {
private final String joinField;

MetaJoinFieldType(String joinField) {
super(NAME, false, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
super(NAME, false, false, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
this.joinField = joinField;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ParentIdFieldMapper build(BuilderContext context) {

public static final class ParentIdFieldType extends StringFieldType {
ParentIdFieldType(String name, boolean eagerGlobalOrdinals, Map<String, String> meta) {
super(name, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
super(name, true, false, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
setEagerGlobalOrdinals(eagerGlobalOrdinals);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public Mapper.Builder<?> parse(String name, Map<String, Object> node, ParserCont

public static final class JoinFieldType extends StringFieldType {
public JoinFieldType(String name, Map<String, String> meta) {
super(name, true, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
super(name, true, false, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static class PercolatorFieldType extends MappedFieldType {
boolean mapUnmappedFieldsAsText;

PercolatorFieldType(String name, Map<String, String> meta) {
super(name, false, false, TextSearchInfo.NONE, meta);
super(name, false, false, false, TextSearchInfo.NONE, meta);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ public static class Defaults {
public static final class CollationFieldType extends StringFieldType {
private final Collator collator;

public CollationFieldType(String name, boolean isSearchable, boolean hasDocValues, Collator collator, Map<String, String> meta) {
super(name, isSearchable, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
public CollationFieldType(String name, boolean isSearchable, boolean isStored, boolean hasDocValues,
Collator collator, Map<String, String> meta) {
super(name, isSearchable, isStored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
setIndexAnalyzer(Lucene.KEYWORD_ANALYZER);
this.collator = collator;
}

public CollationFieldType(String name, Collator collator) {
this(name, true, true, collator, Collections.emptyMap());
this(name, true, false, true, collator, Collections.emptyMap());
}

@Override
Expand Down Expand Up @@ -136,7 +137,7 @@ public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int
}

@Override
public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method,
public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method,
boolean caseInsensitive, QueryShardContext context) {
throw new UnsupportedOperationException("[prefix] queries are not supported on [" + CONTENT_TYPE + "] fields.");
}
Expand Down Expand Up @@ -440,7 +441,8 @@ public Collator buildCollator() {
@Override
public ICUCollationKeywordFieldMapper build(BuilderContext context) {
final Collator collator = buildCollator();
CollationFieldType ft = new CollationFieldType(buildFullName(context), indexed, hasDocValues, collator, meta);
CollationFieldType ft = new CollationFieldType(buildFullName(context), indexed, fieldType.stored(), hasDocValues,
collator, meta);
return new ICUCollationKeywordFieldMapper(name, fieldType, ft,
multiFieldsBuilder.build(this, context), copyTo, rules, language, country, variant, strength, decomposition,
alternate, caseLevel, caseFirst, numeric, variableTop, hiraganaQuaternaryMode, ignoreAbove, collator, nullValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testTermQuery() {

assertEquals(new TermQuery(new Term("field", expected)), ft.termQuery("I WİLL USE TURKİSH CASING", null));

MappedFieldType unsearchable = new CollationFieldType("field", false, true, collator, Collections.emptyMap());
MappedFieldType unsearchable = new CollationFieldType("field", false, false, true, collator, Collections.emptyMap());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> unsearchable.termQuery("bar", null));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
Expand All @@ -86,7 +86,7 @@ public void testTermsQuery() {
assertEquals(new TermInSetQuery("field", terms),
ft.termsQuery(Arrays.asList("foo", "bar"), null));

MappedFieldType unsearchable = new CollationFieldType("field", false, true, collator, Collections.emptyMap());
MappedFieldType unsearchable = new CollationFieldType("field", false, false, true, collator, Collections.emptyMap());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> unsearchable.termsQuery(Arrays.asList("foo", "bar"), null));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
Expand Down Expand Up @@ -135,7 +135,7 @@ public void testRangeQuery() {
assertEquals("[range] queries on [text] or [keyword] fields cannot be executed when " +
"'search.allow_expensive_queries' is set to false.", ee.getMessage());

MappedFieldType unsearchable = new CollationFieldType("field", false, true, DEFAULT_COLLATOR, Collections.emptyMap());
MappedFieldType unsearchable = new CollationFieldType("field", false, false, true, DEFAULT_COLLATOR, Collections.emptyMap());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> unsearchable.rangeQuery("a", "b", false, false, null, null, null, MOCK_QSC));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,6 @@ public void setAnnotations(AnnotatedText annotatedText) {
}
}



@Override
public void reset() throws IOException {
pendingStates.clear();
Expand Down Expand Up @@ -469,6 +467,7 @@ public boolean incrementToken() throws IOException {
return false;
}
}

private void setType(AnnotationToken token) {
//Default annotation type - in future AnnotationTokens may contain custom type info
typeAtt.setType("annotation");
Expand Down Expand Up @@ -515,7 +514,6 @@ private void emitAnnotation(int firstSpannedTextPosInc, int annotationPosLen) th

}


public static final class AnnotatedTextFieldType extends TextFieldMapper.TextFieldType {

public AnnotatedTextFieldType(String name, FieldType fieldType, SimilarityProvider similarity,
Expand All @@ -524,7 +522,7 @@ public AnnotatedTextFieldType(String name, FieldType fieldType, SimilarityProvid
}

public AnnotatedTextFieldType(String name, Map<String, String> meta) {
super(name, true, meta);
super(name, true, false, meta);
}

public void setIndexAnalyzer(NamedAnalyzer delegate, int positionIncrementGap) {
Expand All @@ -542,7 +540,6 @@ public void setIndexAnalyzer(NamedAnalyzer delegate, int positionIncrementGap) {
public String typeName() {
return CONTENT_TYPE;
}

}

private int positionIncrementGap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Builder(String name) {

@Override
public Murmur3FieldMapper build(BuilderContext context) {
return new Murmur3FieldMapper(name, fieldType, new Murmur3FieldType(buildFullName(context), meta),
return new Murmur3FieldMapper(name, fieldType, new Murmur3FieldType(buildFullName(context), fieldType.stored(), meta),
multiFieldsBuilder.build(this, context), copyTo);
}
}
Expand All @@ -97,8 +97,8 @@ public Mapper.Builder<?> parse(String name, Map<String, Object> node, ParserCont

// this only exists so a check can be done to match the field type to using murmur3 hashing...
public static class Murmur3FieldType extends MappedFieldType {
public Murmur3FieldType(String name, Map<String, String> meta) {
super(name, false, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
public Murmur3FieldType(String name, boolean isStored, Map<String, String> meta) {
super(name, false, isStored, true, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ public abstract static class AbstractGeometryFieldType<Parsed, Processed> extend
protected Parser<Parsed> geometryParser;
protected QueryProcessor geometryQueryBuilder;

protected AbstractGeometryFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta) {
super(name, indexed, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
protected AbstractGeometryFieldType(String name, boolean indexed, boolean stored, boolean hasDocValues, Map<String, String> meta) {
super(name, indexed, stored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
}

public void setGeometryQueryBuilder(QueryProcessor geometryQueryBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ public T parse(String name, Map<String, Object> node, Map<String, Object> params

public abstract static class AbstractPointGeometryFieldType<Parsed, Processed>
extends AbstractGeometryFieldType<Parsed, Processed> {
protected AbstractPointGeometryFieldType(String name, boolean indexed, boolean hasDocValues, Map<String, String> meta) {
super(name, indexed, hasDocValues, meta);
protected AbstractPointGeometryFieldType(String name, boolean indexed, boolean stored, boolean hasDocValues,
Map<String, String> meta) {
super(name, indexed, stored, hasDocValues, meta);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ public Builder parse(String name, Map<String, Object> node, Map<String, Object>
public abstract static class AbstractShapeGeometryFieldType<Parsed, Processed> extends AbstractGeometryFieldType<Parsed, Processed> {
protected Orientation orientation = Defaults.ORIENTATION.value();

protected AbstractShapeGeometryFieldType(String name, boolean isSearchable, boolean hasDocValues, Map<String, String> meta) {
super(name, isSearchable, hasDocValues, meta);
protected AbstractShapeGeometryFieldType(String name, boolean isSearchable, boolean isStored, boolean hasDocValues,
Map<String, String> meta) {
super(name, isSearchable, isStored, hasDocValues, meta);
}

public Orientation orientation() { return this.orientation; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public AllFieldMapper build(BuilderContext context) {

static final class AllFieldType extends StringFieldType {
AllFieldType() {
super(NAME, false, false, TextSearchInfo.NONE, Collections.emptyMap());
super(NAME, false, false, false, TextSearchInfo.NONE, Collections.emptyMap());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ public List<Parameter<?>> getParameters() {

@Override
public BinaryFieldMapper build(BuilderContext context) {
return new BinaryFieldMapper(name, new BinaryFieldType(buildFullName(context), hasDocValues.getValue(), meta.getValue()),
multiFieldsBuilder.build(this, context), copyTo.build(), this);
return new BinaryFieldMapper(name, new BinaryFieldType(buildFullName(context), stored.getValue(),
hasDocValues.getValue(), meta.getValue()), multiFieldsBuilder.build(this, context), copyTo.build(), this);
}
}

public static final TypeParser PARSER = new TypeParser((n, c) -> new Builder(n));

public static final class BinaryFieldType extends MappedFieldType {

public BinaryFieldType(String name, boolean hasDocValues, Map<String, String> meta) {
super(name, false, hasDocValues, TextSearchInfo.NONE, meta);
public BinaryFieldType(String name, boolean isStored, boolean hasDocValues, Map<String, String> meta) {
super(name, false, isStored, hasDocValues, TextSearchInfo.NONE, meta);
}

public BinaryFieldType(String name) {
this(name, true, Collections.emptyMap());
this(name, false, true, Collections.emptyMap());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ protected List<Parameter<?>> getParameters() {

@Override
public BooleanFieldMapper build(BuilderContext context) {
MappedFieldType ft = new BooleanFieldType(buildFullName(context), indexed.getValue(), docValues.getValue(), meta.getValue());
MappedFieldType ft = new BooleanFieldType(buildFullName(context), indexed.getValue(), stored.getValue(),
docValues.getValue(), meta.getValue());
ft.setBoost(boost.getValue());
return new BooleanFieldMapper(name, ft, multiFieldsBuilder.build(this, context), copyTo.build(), this);
}
Expand All @@ -110,12 +111,13 @@ public BooleanFieldMapper build(BuilderContext context) {

public static final class BooleanFieldType extends TermBasedFieldType {

public BooleanFieldType(String name, boolean isSearchable, boolean hasDocValues, Map<String, String> meta) {
super(name, isSearchable, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
public BooleanFieldType(String name, boolean isSearchable, boolean isStored, boolean hasDocValues,
Map<String, String> meta) {
super(name, isSearchable, isStored, hasDocValues, TextSearchInfo.SIMPLE_MATCH_ONLY, meta);
}

public BooleanFieldType(String name) {
this(name, true, true, Collections.emptyMap());
this(name, true, false, true, Collections.emptyMap());
}

@Override
Expand Down

0 comments on commit 5ca86d5

Please sign in to comment.