final boolean dedup = uniqueValues != null && uniqueValues.size() * 2 < maxDoc;
if (dedup) {
// we will deduplicate and deref values
boolean success = false;
IndexOutput data = null;
IndexOutput index = null;
String dataName = IndexFileNames.segmentFileName(state.segmentInfo.name + "_" + Integer.toString(field.number), segmentSuffix, "dat");
String indexName = IndexFileNames.segmentFileName(state.segmentInfo.name + "_" + Integer.toString(field.number), segmentSuffix, "idx");
try {
data = dir.createOutput(dataName, state.context);
index = dir.createOutput(indexName, state.context);
if (fixed) {
addFixedDerefBytesField(field, data, index, values, minLength);
} else {
addVarDerefBytesField(field, data, index, values);
}
success = true;
} finally {
if (success) {
IOUtils.close(data, index);
} else {
IOUtils.closeWhileHandlingException(data, index);
}
}
} else {
// we dont deduplicate, just write values straight
if (fixed) {
// fixed byte[]
String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name + "_" + Integer.toString(field.number), segmentSuffix, "dat");
IndexOutput data = dir.createOutput(fileName, state.context);
boolean success = false;
try {
addFixedStraightBytesField(field, data, values, minLength);
success = true;
} finally {
if (success) {
IOUtils.close(data);
} else {
IOUtils.closeWhileHandlingException(data);
}
}
} else {
// variable byte[]
boolean success = false;
IndexOutput data = null;
IndexOutput index = null;
String dataName = IndexFileNames.segmentFileName(state.segmentInfo.name + "_" + Integer.toString(field.number), segmentSuffix, "dat");
String indexName = IndexFileNames.segmentFileName(state.segmentInfo.name + "_" + Integer.toString(field.number), segmentSuffix, "idx");
try {
data = dir.createOutput(dataName, state.context);
index = dir.createOutput(indexName, state.context);