Skip to content

Commit

Permalink
Remove DocumentFieldMappers#smartNameFieldMapper, as it is no longer …
Browse files Browse the repository at this point in the history
…needed. (#31018)
  • Loading branch information
jtibshirani authored Jun 8, 2018
1 parent 2378fa1 commit 8f60707
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public void testMerge() throws IOException {
new CompressedXContent(stage2Mapping), MapperService.MergeReason.MAPPING_UPDATE);

// previous mapper has not been modified
assertThat(((TokenCountFieldMapper) stage1.mappers().smartNameFieldMapper("tc")).analyzer(), equalTo("keyword"));
assertThat(((TokenCountFieldMapper) stage1.mappers().getMapper("tc")).analyzer(), equalTo("keyword"));
// but the new one has the change
assertThat(((TokenCountFieldMapper) stage2.mappers().smartNameFieldMapper("tc")).analyzer(), equalTo("standard"));
assertThat(((TokenCountFieldMapper) stage2.mappers().getMapper("tc")).analyzer(), equalTo("standard"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static Map<String, FieldMappingMetaData> findFieldMappingsByType(Predica
}
} else {
// not a pattern
FieldMapper fieldMapper = allFieldMappers.smartNameFieldMapper(field);
FieldMapper fieldMapper = allFieldMappers.getMapper(field);
if (fieldMapper != null) {
addFieldMapper(fieldPredicate, field, fieldMapper, fieldMappings, request.includeDefaults());
} else if (request.probablySingleFieldRequest()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private GetResult innerGetLoadFromStoredFields(String type, String id, String[]

if (gFields != null && gFields.length > 0) {
for (String field : gFields) {
FieldMapper fieldMapper = docMapper.mappers().smartNameFieldMapper(field);
FieldMapper fieldMapper = docMapper.mappers().getMapper(field);
if (fieldMapper == null) {
if (docMapper.objectMappers().get(field) != null) {
// Only fail if we know it is a object field, missing paths / fields shouldn't fail.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,6 @@ public Collection<String> simpleMatchToFullName(String pattern) {
return fields;
}

public FieldMapper smartNameFieldMapper(String name) {
FieldMapper fieldMapper = getMapper(name);
if (fieldMapper != null) {
return fieldMapper;
}
for (FieldMapper otherFieldMapper : this) {
if (otherFieldMapper.fieldType().name().equals(name)) {
return otherFieldMapper;
}
}
return null;
}

/**
* A smart analyzer used for indexing that takes into account specific analyzers configured
* per {@link FieldMapper}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static Map<String, Float> parseFieldsAndWeights(List<String> fields) {
public static FieldMapper getFieldMapper(MapperService mapperService, String field) {
DocumentMapper mapper = mapperService.documentMapper();
if (mapper != null) {
FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper(field);
FieldMapper fieldMapper = mapper.mappers().getMapper(field);
if (fieldMapper != null) {
return fieldMapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testDefaultMapping() throws Exception {

DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));

FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper("field");
FieldMapper fieldMapper = mapper.mappers().getMapper("field");
assertThat(fieldMapper, instanceOf(BinaryFieldMapper.class));
assertThat(fieldMapper.fieldType().stored(), equalTo(false));
}
Expand Down Expand Up @@ -94,7 +94,7 @@ public void testStoredValue() throws IOException {
XContentType.JSON));
BytesRef indexedValue = doc.rootDoc().getBinaryValue("field");
assertEquals(new BytesRef(value), indexedValue);
FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper("field");
FieldMapper fieldMapper = mapper.mappers().getMapper("field");
Object originalValue = fieldMapper.fieldType().valueForDisplay(indexedValue);
assertEquals(new BytesArray(value), originalValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public void test1Merge() throws Exception {

DocumentMapper merged = stage1.merge(stage2.mapping());
// stage1 mapping should not have been modified
assertThat(stage1.mappers().smartNameFieldMapper("age"), nullValue());
assertThat(stage1.mappers().smartNameFieldMapper("obj1.prop1"), nullValue());
assertThat(stage1.mappers().getMapper("age"), nullValue());
assertThat(stage1.mappers().getMapper("obj1.prop1"), nullValue());
// but merged should
assertThat(merged.mappers().smartNameFieldMapper("age"), notNullValue());
assertThat(merged.mappers().smartNameFieldMapper("obj1.prop1"), notNullValue());
assertThat(merged.mappers().getMapper("age"), notNullValue());
assertThat(merged.mappers().getMapper("obj1.prop1"), notNullValue());
}

public void testMergeObjectDynamic() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,25 @@ public void testDoubleIndexingSameDoc() throws Exception {
IndexReader reader = DirectoryReader.open(writer);
IndexSearcher searcher = new IndexSearcher(reader);

TopDocs topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field1").fieldType().termQuery("value1", context), 10);
TopDocs topDocs = searcher.search(mapper.mappers().getMapper("field1").fieldType().termQuery("value1", context), 10);
assertThat(topDocs.totalHits, equalTo(2L));

topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field2").fieldType().termQuery("1", context), 10);
topDocs = searcher.search(mapper.mappers().getMapper("field2").fieldType().termQuery("1", context), 10);
assertThat(topDocs.totalHits, equalTo(2L));

topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field3").fieldType().termQuery("1.1", context), 10);
topDocs = searcher.search(mapper.mappers().getMapper("field3").fieldType().termQuery("1.1", context), 10);
assertThat(topDocs.totalHits, equalTo(2L));

topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field4").fieldType().termQuery("2010-01-01", context), 10);
topDocs = searcher.search(mapper.mappers().getMapper("field4").fieldType().termQuery("2010-01-01", context), 10);
assertThat(topDocs.totalHits, equalTo(2L));

topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field5").fieldType().termQuery("1", context), 10);
topDocs = searcher.search(mapper.mappers().getMapper("field5").fieldType().termQuery("1", context), 10);
assertThat(topDocs.totalHits, equalTo(2L));

topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field5").fieldType().termQuery("2", context), 10);
topDocs = searcher.search(mapper.mappers().getMapper("field5").fieldType().termQuery("2", context), 10);
assertThat(topDocs.totalHits, equalTo(2L));

topDocs = searcher.search(mapper.mappers().smartNameFieldMapper("field5").fieldType().termQuery("3", context), 10);
topDocs = searcher.search(mapper.mappers().getMapper("field5").fieldType().termQuery("3", context), 10);
assertThat(topDocs.totalHits, equalTo(2L));
writer.close();
reader.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,10 @@ public void testNumericDetectionEnabled() throws Exception {
.setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();

defaultMapper = index.mapperService().documentMapper("type");
FieldMapper mapper = defaultMapper.mappers().smartNameFieldMapper("s_long");
FieldMapper mapper = defaultMapper.mappers().getMapper("s_long");
assertThat(mapper.fieldType().typeName(), equalTo("long"));

mapper = defaultMapper.mappers().smartNameFieldMapper("s_double");
mapper = defaultMapper.mappers().getMapper("s_double");
assertThat(mapper.fieldType().typeName(), equalTo("float"));
}

Expand All @@ -652,10 +652,10 @@ public void testNumericDetectionDefault() throws Exception {
.setSource(doc.dynamicMappingsUpdate().toString(), XContentType.JSON).get());

defaultMapper = index.mapperService().documentMapper("type");
FieldMapper mapper = defaultMapper.mappers().smartNameFieldMapper("s_long");
FieldMapper mapper = defaultMapper.mappers().getMapper("s_long");
assertThat(mapper, instanceOf(TextFieldMapper.class));

mapper = defaultMapper.mappers().smartNameFieldMapper("s_double");
mapper = defaultMapper.mappers().getMapper("s_double");
assertThat(mapper, instanceOf(TextFieldMapper.class));
}

Expand Down Expand Up @@ -703,9 +703,9 @@ public void testDateDetectionInheritsFormat() throws Exception {

defaultMapper = index.mapperService().documentMapper("type");

DateFieldMapper dateMapper1 = (DateFieldMapper) defaultMapper.mappers().smartNameFieldMapper("date1");
DateFieldMapper dateMapper2 = (DateFieldMapper) defaultMapper.mappers().smartNameFieldMapper("date2");
DateFieldMapper dateMapper3 = (DateFieldMapper) defaultMapper.mappers().smartNameFieldMapper("date3");
DateFieldMapper dateMapper1 = (DateFieldMapper) defaultMapper.mappers().getMapper("date1");
DateFieldMapper dateMapper2 = (DateFieldMapper) defaultMapper.mappers().getMapper("date2");
DateFieldMapper dateMapper3 = (DateFieldMapper) defaultMapper.mappers().getMapper("date3");
// inherited from dynamic date format
assertEquals("yyyy-MM-dd", dateMapper1.fieldType().dateTimeFormatter().format());
// inherited from dynamic date format since the mapping in the template did not specify a format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public void testMatchTypeOnly() throws Exception {
docMapper = index.mapperService().documentMapper("person");
DocumentFieldMappers mappers = docMapper.mappers();

assertThat(mappers.smartNameFieldMapper("s"), Matchers.notNullValue());
assertEquals(IndexOptions.NONE, mappers.smartNameFieldMapper("s").fieldType().indexOptions());
assertThat(mappers.getMapper("s"), Matchers.notNullValue());
assertEquals(IndexOptions.NONE, mappers.getMapper("s").fieldType().indexOptions());

assertThat(mappers.smartNameFieldMapper("l"), Matchers.notNullValue());
assertNotSame(IndexOptions.NONE, mappers.smartNameFieldMapper("l").fieldType().indexOptions());
assertThat(mappers.getMapper("l"), Matchers.notNullValue());
assertNotSame(IndexOptions.NONE, mappers.getMapper("l").fieldType().indexOptions());


}
Expand Down

0 comments on commit 8f60707

Please sign in to comment.