LUCENE-3606: clean up more cruft

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3606@1210277 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2011-12-04 23:31:32 +00:00
parent 5586ca1912
commit a7bc061caa
3 changed files with 25 additions and 63 deletions

View File

@ -48,7 +48,7 @@ public final class SegmentInfo implements Cloneable {
// TODO: remove these from this class, for now this is the representation // TODO: remove these from this class, for now this is the representation
public static final int NO = -1; // e.g. no norms; no deletes; public static final int NO = -1; // e.g. no norms; no deletes;
public static final int YES = 1; // e.g. have norms; have deletes; public static final int YES = 1; // e.g. have norms; have deletes;
static final int WITHOUT_GEN = 0; // a file name that has no GEN in it. public static final int WITHOUT_GEN = 0; // a file name that has no GEN in it.
public String name; // unique name in dir public String name; // unique name in dir
public int docCount; // number of docs in seg public int docCount; // number of docs in seg
@ -336,18 +336,6 @@ public final class SegmentInfo implements Cloneable {
} }
} }
/**
* @deprecated separate norms are not supported in >= 4.0
*/
public boolean hasSeparateNorms(int fieldNumber) {
if (normGen == null) {
return false;
}
Long gen = normGen.get(fieldNumber);
return gen != null && gen.longValue() != NO;
}
/** /**
* @deprecated separate norms are not supported in >= 4.0 * @deprecated separate norms are not supported in >= 4.0
*/ */
@ -365,42 +353,6 @@ public final class SegmentInfo implements Cloneable {
return false; return false;
} }
void initNormGen() {
if (normGen == null) { // normGen is null if this segments file hasn't had any norms set against it yet
normGen = new HashMap<Integer, Long>();
}
}
/**
* Increment the generation count for the norms file for
* this field.
*
* @param fieldIndex field whose norm file will be rewritten
*/
void advanceNormGen(int fieldIndex) {
Long gen = normGen.get(fieldIndex);
if (gen == null || gen.longValue() == NO) {
normGen.put(fieldIndex, new Long(YES));
} else {
normGen.put(fieldIndex, gen+1);
}
clearFilesCache();
}
/**
* Get the file name for the norms file for this field.
*
* @param number field index
*/
public String getNormFileName(int number) {
if (hasSeparateNorms(number)) {
return IndexFileNames.fileNameFromGeneration(name, IndexFileNames.SEPARATE_NORMS_EXTENSION + number, normGen.get(number));
} else {
// single file for all norms
return IndexFileNames.fileNameFromGeneration(name, IndexFileNames.NORMS_EXTENSION, WITHOUT_GEN);
}
}
/** /**
* Mark whether this segment is stored as a compound file. * Mark whether this segment is stored as a compound file.
* *

View File

@ -208,26 +208,16 @@ public class SegmentReader extends IndexReader implements Cloneable {
ensureOpen(); ensureOpen();
boolean deletionsUpToDate = (this.si.hasDeletions() == si.hasDeletions()) boolean deletionsUpToDate = (this.si.hasDeletions() == si.hasDeletions())
&& (!si.hasDeletions() || this.si.getDelFileName().equals(si.getDelFileName())); && (!si.hasDeletions() || this.si.getDelFileName().equals(si.getDelFileName()));
boolean normsUpToDate = true;
Set<Integer> fieldNormsChanged = new HashSet<Integer>();
for (FieldInfo fi : core.fieldInfos) {
int fieldNumber = fi.number;
if (!this.si.getNormFileName(fieldNumber).equals(si.getNormFileName(fieldNumber))) {
normsUpToDate = false;
fieldNormsChanged.add(fieldNumber);
}
}
// if we're cloning we need to run through the reopenSegment logic // if we're cloning we need to run through the reopenSegment logic
// also if both old and new readers aren't readonly, we clone to avoid sharing modifications // also if both old and new readers aren't readonly, we clone to avoid sharing modifications
if (normsUpToDate && deletionsUpToDate && !doClone && openReadOnly && readOnly) { if (deletionsUpToDate && !doClone && openReadOnly && readOnly) {
return null; return null;
} }
// When cloning, the incoming SegmentInfos should not // When cloning, the incoming SegmentInfos should not
// have any changes in it: // have any changes in it:
assert !doClone || (normsUpToDate && deletionsUpToDate); assert !doClone || (deletionsUpToDate);
// clone reader // clone reader
SegmentReader clone = new SegmentReader(); SegmentReader clone = new SegmentReader();

View File

@ -48,13 +48,15 @@ public class Lucene40NormsReader extends NormsReader {
// but we just don't do any seeks or reading yet. // but we just don't do any seeks or reading yet.
public Lucene40NormsReader(Directory dir, SegmentInfo info, FieldInfos fields, IOContext context, Directory separateNormsDir) throws IOException { public Lucene40NormsReader(Directory dir, SegmentInfo info, FieldInfos fields, IOContext context, Directory separateNormsDir) throws IOException {
maxdoc = info.docCount; maxdoc = info.docCount;
String segmentName = info.name;
Map<Integer,Long> normGen = info.getNormGen();
boolean success = false; boolean success = false;
try { try {
long nextNormSeek = Lucene40NormsWriter.NORMS_HEADER.length; //skip header (header unused for now) long nextNormSeek = Lucene40NormsWriter.NORMS_HEADER.length; //skip header (header unused for now)
for (FieldInfo fi : fields) { for (FieldInfo fi : fields) {
if (fi.isIndexed && !fi.omitNorms) { if (fi.isIndexed && !fi.omitNorms) {
String fileName = info.getNormFileName(fi.number); String fileName = getNormFilename(segmentName, normGen, fi.number);
Directory d = info.hasSeparateNorms(fi.number) ? separateNormsDir : dir; Directory d = hasSeparateNorms(normGen, fi.number) ? separateNormsDir : dir;
// singleNormFile means multiple norms share this file // singleNormFile means multiple norms share this file
boolean singleNormFile = IndexFileNames.matchesExtension(fileName, IndexFileNames.NORMS_EXTENSION); boolean singleNormFile = IndexFileNames.matchesExtension(fileName, IndexFileNames.NORMS_EXTENSION);
@ -127,6 +129,24 @@ public class Lucene40NormsReader extends NormsReader {
} }
} }
private static String getNormFilename(String segmentName, Map<Integer,Long> normGen, int number) {
if (hasSeparateNorms(normGen, number)) {
return IndexFileNames.fileNameFromGeneration(segmentName, IndexFileNames.SEPARATE_NORMS_EXTENSION + number, normGen.get(number));
} else {
// single file for all norms
return IndexFileNames.fileNameFromGeneration(segmentName, IndexFileNames.NORMS_EXTENSION, SegmentInfo.WITHOUT_GEN);
}
}
private static boolean hasSeparateNorms(Map<Integer,Long> normGen, int number) {
if (normGen == null) {
return false;
}
Long gen = normGen.get(number);
return gen != null && gen.longValue() != SegmentInfo.NO;
}
class Norm { class Norm {
IndexInput file; IndexInput file;
long offset; long offset;