diff --git a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsReader.java index b16e3942cd3..0b40f825f00 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsReader.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempFSTTermsReader.java @@ -20,6 +20,8 @@ package org.apache.lucene.codecs.temp; import java.io.IOException; import java.io.PrintWriter; import java.io.File; +import java.util.ArrayList; +import java.util.BitSet; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; @@ -164,7 +166,7 @@ public class TempFSTTermsReader extends FieldsProducer { this.docCount = docCount; this.longsSize = longsSize; this.dict = new FST(in, new TempTermOutputs(fieldInfo, longsSize)); - //PrintWriter pw = new PrintWriter(new File("../graphs/ohohoh."+tmpname+".xxx.txt")); + //PrintWriter pw = new PrintWriter(new File("ohohoh."+tmpname+".xxx.txt")); //Util.toDot(dict, pw, false, false); //pw.close(); } @@ -296,7 +298,6 @@ public class TempFSTTermsReader extends FieldsProducer { seekPending = false; } - // nocommit: reuse? @Override public DocsEnum docs(Bits liveDocs, DocsEnum reuse, int flags) throws IOException { decodeMetaData(); @@ -363,4 +364,28 @@ public class TempFSTTermsReader extends FieldsProducer { } } } + static void walk(FST fst) throws IOException { + final ArrayList> queue = new ArrayList>(); + final BitSet seen = new BitSet(); + final FST.BytesReader reader = fst.getBytesReader(); + final FST.Arc startArc = fst.getFirstArc(new FST.Arc()); + queue.add(startArc); + while (!queue.isEmpty()) { + final FST.Arc arc = queue.remove(0); + final long node = arc.target; + //System.out.println(arc); + if (FST.targetHasArcs(arc) && !seen.get((int) node)) { + //seen.set((int) node); + fst.readFirstRealTargetArc(node, arc, reader); + while (true) { + queue.add(new FST.Arc().copyFrom(arc)); + if (arc.isLast()) { + break; + } else { + fst.readNextRealArc(arc, reader); + } + } + } + } + } } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempTermOutputs.java b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempTermOutputs.java index 0e2a1c88057..6d3419fef8b 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/temp/TempTermOutputs.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/temp/TempTermOutputs.java @@ -246,9 +246,15 @@ public class TempTermOutputs extends Outputs { out.writeBytes(data.bytes, 0, data.bytes.length); } if (bit2 > 0) { // stats exist - out.writeVInt(data.docFreq); if (hasPos) { - out.writeVLong(data.totalTermFreq - data.docFreq); + if (data.docFreq == data.totalTermFreq) { + out.writeVInt((data.docFreq << 1) | 1); + } else { + out.writeVInt((data.docFreq << 1)); + out.writeVLong(data.totalTermFreq - data.docFreq); + } + } else { + out.writeVInt(data.docFreq); } } } @@ -277,9 +283,14 @@ public class TempTermOutputs extends Outputs { in.readBytes(bytes, 0, bytesSize); } if (bit2 > 0) { // stats exist - docFreq = in.readVInt(); + int code = in.readVInt(); if (hasPos) { - totalTermFreq = docFreq + in.readVLong(); + totalTermFreq = docFreq = code >>> 1; + if ((code & 1) == 0) { + totalTermFreq += in.readVLong(); + } + } else { + docFreq = code; } } return new TempMetaData(longs, bytes, docFreq, totalTermFreq);