byte[] source = extractSource(doc, documentMapper);
// get the version
InternalSearchHit searchHit = new InternalSearchHit(docId, uid.id(), uid.type(), source, null);
hits[index] = searchHit;
for (Object oField : doc.getFields()) {
Fieldable field = (Fieldable) oField;
String name = field.name();
// ignore UID, we handled it above
if (name.equals(UidFieldMapper.NAME)) {
continue;
}
// ignore source, we handled it above
if (name.equals(SourceFieldMapper.NAME)) {
continue;
}
Object value = null;
FieldMappers fieldMappers = documentMapper.mappers().indexName(field.name());
if (fieldMappers != null) {
FieldMapper mapper = fieldMappers.mapper();
if (mapper != null) {
name = mapper.names().fullName();
value = mapper.valueForSearch(field);
}
}
if (value == null) {
if (field.isBinary()) {
value = field.getBinaryValue();
} else {
value = field.stringValue();
}
}
if (searchHit.fieldsOrNull() == null) {
searchHit.fields(new HashMap<String, SearchHitField>(2));
}
SearchHitField hitField = searchHit.fields().get(name);
if (hitField == null) {
hitField = new InternalSearchHitField(name, new ArrayList<Object>(2));
searchHit.fields().put(name, hitField);
}
hitField.values().add(value);
}
int readerIndex = context.searcher().readerIndex(docId);