You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2013/07/25 20:21:59 UTC
svn commit: r1507083 -
/lucene/dev/branches/lucene5127/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java
Author: rmuir
Date: Thu Jul 25 18:21:59 2013
New Revision: 1507083
URL: http://svn.apache.org/r1507083
Log:
LUCENE-5127: simplify vargap
Modified:
lucene/dev/branches/lucene5127/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java
Modified: lucene/dev/branches/lucene5127/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5127/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java?rev=1507083&r1=1507082&r2=1507083&view=diff
==============================================================================
--- lucene/dev/branches/lucene5127/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java (original)
+++ lucene/dev/branches/lucene5127/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java Thu Jul 25 18:21:59 2013
@@ -32,8 +32,7 @@ import org.apache.lucene.store.Directory
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IntsRef;
-import org.apache.lucene.util.fst.Builder;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.fst.BytesRefFSTEnum;
import org.apache.lucene.util.fst.FST;
import org.apache.lucene.util.fst.PositiveIntOutputs;
@@ -45,11 +44,6 @@ import org.apache.lucene.util.fst.Util;
public class VariableGapTermsIndexReader extends TermsIndexReaderBase {
private final PositiveIntOutputs fstOutputs = PositiveIntOutputs.getSingleton();
- private int indexDivisor;
-
- // Closed if indexLoaded is true:
- private IndexInput in;
- private volatile boolean indexLoaded;
final HashMap<FieldInfo,FieldIndexData> fields = new HashMap<FieldInfo,FieldIndexData>();
@@ -61,10 +55,9 @@ public class VariableGapTermsIndexReader
final String segment;
public VariableGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, String segmentSuffix, IOContext context)
throws IOException {
- in = dir.openInput(IndexFileNames.segmentFileName(segment, segmentSuffix, VariableGapTermsIndexWriter.TERMS_INDEX_EXTENSION), new IOContext(context, true));
+ final IndexInput in = dir.openInput(IndexFileNames.segmentFileName(segment, segmentSuffix, VariableGapTermsIndexWriter.TERMS_INDEX_EXTENSION), new IOContext(context, true));
this.segment = segment;
boolean success = false;
- this.indexDivisor = 1; // nocommit
try {
@@ -82,19 +75,17 @@ public class VariableGapTermsIndexReader
final int field = in.readVInt();
final long indexStart = in.readVLong();
final FieldInfo fieldInfo = fieldInfos.fieldInfo(field);
- FieldIndexData previous = fields.put(fieldInfo, new FieldIndexData(fieldInfo, indexStart));
+ FieldIndexData previous = fields.put(fieldInfo, new FieldIndexData(in, fieldInfo, indexStart));
if (previous != null) {
throw new CorruptIndexException("duplicate field: " + fieldInfo.name + " (resource=" + in + ")");
}
}
success = true;
} finally {
- if (indexDivisor > 0) {
- in.close();
- in = null;
- if (success) {
- indexLoaded = true;
- }
+ if (success) {
+ IOUtils.close(in);
+ } else {
+ IOUtils.closeWhileHandlingException(in);
}
}
}
@@ -162,52 +153,21 @@ public class VariableGapTermsIndexReader
}
private final class FieldIndexData {
+ private final FST<Long> fst;
- private final long indexStart;
- // Set only if terms index is loaded:
- private volatile FST<Long> fst;
-
- public FieldIndexData(FieldInfo fieldInfo, long indexStart) throws IOException {
- this.indexStart = indexStart;
-
- if (indexDivisor > 0) {
- loadTermsIndex();
- }
- }
-
- private void loadTermsIndex() throws IOException {
- if (fst == null) {
- IndexInput clone = in.clone();
- clone.seek(indexStart);
- fst = new FST<Long>(clone, fstOutputs);
- clone.close();
-
- /*
- final String dotFileName = segment + "_" + fieldInfo.name + ".dot";
- Writer w = new OutputStreamWriter(new FileOutputStream(dotFileName));
- Util.toDot(fst, w, false, false);
- System.out.println("FST INDEX: SAVED to " + dotFileName);
- w.close();
- */
-
- if (indexDivisor > 1) {
- // subsample
- final IntsRef scratchIntsRef = new IntsRef();
- final PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
- final Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE1, outputs);
- final BytesRefFSTEnum<Long> fstEnum = new BytesRefFSTEnum<Long>(fst);
- BytesRefFSTEnum.InputOutput<Long> result;
- int count = indexDivisor;
- while((result = fstEnum.next()) != null) {
- if (count == indexDivisor) {
- builder.add(Util.toIntsRef(result.input, scratchIntsRef), result.output);
- count = 0;
- }
- count++;
- }
- fst = builder.finish();
- }
- }
+ public FieldIndexData(IndexInput in, FieldInfo fieldInfo, long indexStart) throws IOException {
+ IndexInput clone = in.clone();
+ clone.seek(indexStart);
+ fst = new FST<Long>(clone, fstOutputs);
+ clone.close();
+
+ /*
+ final String dotFileName = segment + "_" + fieldInfo.name + ".dot";
+ Writer w = new OutputStreamWriter(new FileOutputStream(dotFileName));
+ Util.toDot(fst, w, false, false);
+ System.out.println("FST INDEX: SAVED to " + dotFileName);
+ w.close();
+ */
}
}
@@ -222,11 +182,7 @@ public class VariableGapTermsIndexReader
}
@Override
- public void close() throws IOException {
- if (in != null && !indexLoaded) {
- in.close();
- }
- }
+ public void close() throws IOException {}
private void seekDir(IndexInput input, long dirOffset) throws IOException {
if (version >= VariableGapTermsIndexWriter.VERSION_APPEND_ONLY) {