this.mappedFields = new MappedFields(context);
if (!context.hasFieldNames()) {
if (context.hasPartialFields()) {
// partial fields need the source, so fetch it,
// but don't return it
fieldsVisitor = new UidAndSourceFieldsVisitor();
} else if (context.hasScriptFields()) {
// we ask for script fields, and no field names,
// don't load the source
fieldsVisitor = new JustUidFieldsVisitor();
} else {
sourceRequested = true;
fieldsVisitor = new UidAndSourceFieldsVisitor();
}
} else if (context.fieldNames().isEmpty()) {
fieldsVisitor = new JustUidFieldsVisitor();
} else {
boolean loadAllStored = false;
Set<String> fieldNames = null;
for (String fieldName : context.fieldNames()) {
if (fieldName.equals("*")) {
loadAllStored = true;
continue;
}
if (fieldName.equals(SourceFieldMapper.NAME)) {
sourceRequested = true;
continue;
}
FieldMappers x = context.smartNameFieldMappers(fieldName);
if (x != null && x.mapper().fieldType().stored()) {
if (fieldNames == null) {
fieldNames = new HashSet<String>();
}
fieldNames.add(x.mapper().names().indexName());
} else {
if (extractFieldNames == null) {
extractFieldNames = newArrayList();
}
extractFieldNames.add(fieldName);
}
}
if (loadAllStored) {
if (sourceRequested || extractFieldNames != null) {
fieldsVisitor = new CustomFieldsVisitor(true,
true); // load
// everything,
// including
// _source
} else {
fieldsVisitor = new CustomFieldsVisitor(true, false);
}
} else if (fieldNames != null) {
boolean loadSource = extractFieldNames != null ||
sourceRequested;
fieldsVisitor = new CustomFieldsVisitor(fieldNames,
loadSource);
} else if (extractFieldNames != null || sourceRequested) {
fieldsVisitor = new UidAndSourceFieldsVisitor();
} else {
fieldsVisitor = new JustUidFieldsVisitor();
}
}