Tests: Add type-unrestricted version of field mapper getter to SearchContext.

This fixes an NPE when using TestSearchContext in SignificanceHeuristicTests.
This commit is contained in:
Ryan Ernst 2015-01-29 13:22:46 -08:00
parent ecc8b702d3
commit 1ebc95ee28
6 changed files with 37 additions and 2 deletions

View File

@ -663,6 +663,11 @@ public class PercolateContext extends SearchContext {
return mapperService().smartNameFieldMapper(name, types);
}
@Override
public FieldMapper smartNameFieldMapperFromAnyType(String name) {
return mapperService().smartNameFieldMapper(name);
}
@Override
public MapperService.SmartNameObjectMapper smartNameObjectMapper(String name) {
throw new UnsupportedOperationException();

View File

@ -152,7 +152,7 @@ public class ValuesSourceParser<VS extends ValuesSource> {
return config;
}
FieldMapper<?> mapper = context.mapperService().smartNameFieldMapper(input.field);
FieldMapper<?> mapper = context.smartNameFieldMapperFromAnyType(input.field);
if (mapper == null) {
Class<VS> valuesSourceType = valueType != null ? (Class<VS>) valueType.getValuesSourceType() : this.valuesSourceType;
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType);

View File

@ -671,18 +671,27 @@ public class DefaultSearchContext extends SearchContext {
return scanContext;
}
@Override
public MapperService.SmartNameFieldMappers smartFieldMappers(String name) {
return mapperService().smartName(name, request.types());
}
@Override
public FieldMappers smartNameFieldMappers(String name) {
return mapperService().smartNameFieldMappers(name, request.types());
}
@Override
public FieldMapper smartNameFieldMapper(String name) {
return mapperService().smartNameFieldMapper(name, request.types());
}
@Override
public FieldMapper smartNameFieldMapperFromAnyType(String name) {
return mapperService().smartNameFieldMapper(name);
}
@Override
public MapperService.SmartNameObjectMapper smartNameObjectMapper(String name) {
return mapperService().smartNameObjectMapper(name, request.types());
}

View File

@ -548,6 +548,11 @@ public abstract class FilteredSearchContext extends SearchContext {
return in.smartNameFieldMapper(name);
}
@Override
public FieldMapper smartNameFieldMapperFromAnyType(String name) {
return in.smartNameFieldMapperFromAnyType(name);
}
@Override
public MapperService.SmartNameObjectMapper smartNameObjectMapper(String name) {
return in.smartNameObjectMapper(name);

View File

@ -349,6 +349,11 @@ public abstract class SearchContext implements Releasable {
public abstract FieldMapper smartNameFieldMapper(String name);
/**
* Looks up the given field, but does not restrict to fields in the types set on this context.
*/
public abstract FieldMapper smartNameFieldMapperFromAnyType(String name);
public abstract MapperService.SmartNameObjectMapper smartNameObjectMapper(String name);
public abstract Counter timeEstimateCounter();

View File

@ -570,9 +570,20 @@ public class TestSearchContext extends SearchContext {
return null;
}
@Override
public FieldMapper<?> smartNameFieldMapperFromAnyType(String name) {
if (mapperService() != null) {
return mapperService().smartNameFieldMapper(name);
}
return null;
}
@Override
public MapperService.SmartNameObjectMapper smartNameObjectMapper(String name) {
return mapperService().smartNameObjectMapper(name, types);
if (mapperService() != null) {
return mapperService().smartNameObjectMapper(name, types);
}
return null;
}
@Override